/// <summary> /// SSL加密发送邮件From:www.uzhanbao.com /// </summary> /// <param name="sto"></param> /// <param name="sToSubject"></param> /// <param name="sContent"></param> /// <returns></returns> public string SendEmailSSL(string sto, string sToSubject, string sContent) { string sRestring = ""; try {
string sSmtp = "smtp.office365.com"; string sPort = "587"; string sFrom = "web@uzhanbao.com"; string sAccount = "web@uzhanbao.com"; string sPass = "web122";
System.Net.Mail.SmtpClient client = new SmtpClient(); client.Host = sSmtp; client.UseDefaultCredentials = false; client.Port = Convert.ToInt16(sPort); client.Credentials = new System.Net.NetworkCredential(sAccount, sPass); client.EnableSsl = true; //星号改成自己邮箱的密码 //client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage(sFrom, sto);
message.Subject = sToSubject; message.Body = sContent; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true;
//添加附件 //Attachment data = new Attachment(@"附件地址如:e:/a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet); //message.Attachments.Add(data);
client.Send(message); sRestring = "ok"; } catch (Exception ex) { sRestring = "failed," + ex.Message.ToString(); }
return sRestring; }