Email

 

<appSettings>
    <add key="EmailAcount" value="xxxx"/>
    <add key="EmailPassword" value="xxxx"/>
    <add key="Mail_Smtp" value="xxxx"/>
  </appSettings>

 注意:输入邮箱的前后空格

private void NewMethod(string emailSendFrom, string emailSendFromTo, string subject, string content)
        {
            var emailAcount = ConfigurationManager.AppSettings["EmailAcount"];//获取发送邮箱用户名
            var emailPassword = ConfigurationManager.AppSettings["EmailPassword"];//获取发送邮箱密码
            var emailSmtp = ConfigurationManager.AppSettings["Mail_Smtp"];//获取邮箱发送服务器
            MailMessage message = new MailMessage(emailSendFrom, emailSendFromTo); //创建邮箱对象
            //MailAddress fromAddr = new MailAddress("sunhaiming@cn.wilmar-intl.com");//发件人
            //message.From = fromAddr;
            //message.To.Add(reciver);
            message.Subject = subject;
            message.Body = content;
            message.BodyEncoding = Encoding.UTF8;
            SmtpClient client = new SmtpClient(emailSmtp, 587);//smtp端口
            client.Credentials = new NetworkCredential(emailAcount, emailPassword);//获取邮箱用户名及密码
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.EnableSsl = true;//判断验证方式
            try
            {
                client.Send(message);//发送信息
            }
            catch (System.Net.Mail.SmtpException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
View Code

 

 

 
 

 

 

posted on 2016-09-27 09:59  路上有你F  阅读(484)  评论(0编辑  收藏  举报