ASP.NET 如何通过浏览器发送指定的QQ邮件

源码如下:

//MVC验证码获取

        //保存验证码

        public static string InputVerificationCode = "";

        protected void Button1_Click1(object sender, EventArgs e)

        {

            try

            {

                //随机数0~10产生六位验证码

                Random random = new Random();

                for (int i = 0; i < 6; i++)

                {

                    InputVerificationCode += random.Next(10).ToString();

                }

                //设置发送方的邮件信息,例如使用网易的smtp

                string smtpServer = "smtp.qq.com";//SMTP服务器

                string mailFrom = "jfblackbird@foxmail.com";//登录用户名

                string userpassword = "ltzmudrssqzfhihe";//登录密码


                //邮件服务设置

                SmtpClient smtpClient = new SmtpClient();

                //指定电子邮件发送方式;

                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                //指定SMTP服务器

                smtpClient.Host = smtpServer;

                //用户名和密码

                smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userpassword);

                //发送邮件设置

                //发送人和收件人

                MailMessage mailMessage = new MailMessage(mailFrom, this.txt_eamil.Value);

                //邮件主题

                mailMessage.Subject = "";

                //邮件内容

                mailMessage.Body = "尊敬的用户您好!您正在操作注册众筹之家账号,验证码为:" + InputVerificationCode + "。如果不是本人操作,请勿泄露验证码!";

                //正文编码

                mailMessage.BodyEncoding = Encoding.UTF8;

                //设置为HTML格式

                mailMessage.IsBodyHtml = true;

                //设置优先级

                mailMessage.Priority = MailPriority.Low;

                //发送邮件

                smtpClient.Send(mailMessage);

            }

            catch (SmtpException ex)

            {

                //Response.Write("<script>alert('" + ex.Message + "')</script>");

                //this.txt_accounts.Text = null;

                //this.txt_pwd.Text = null;

                //this.txt_repwd.Text = null;

                //this.txt_youxiang.Text = null;

                //this.TextBox1.Text = null;

            }

        }

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容