C#-Stmp发邮件
生活随笔
收集整理的這篇文章主要介紹了
C#-Stmp发邮件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
public MailMessage Initial(string Address){MailMessage m_Mail = new MailMessage();//發(fā)件人m_Mail.From = new MailAddress("wawd74520@tom.com");//收件人m_Mail.To.Add(new MailAddress(Address));//主題m_Mail.Subject ="代理好久沒驗證了!!!";//內(nèi)容m_Mail.Body = "趕緊重開一下吧!!!";//郵件主題和正文編碼格式m_Mail.SubjectEncoding = System.Text.Encoding.UTF8;m_Mail.BodyEncoding = System.Text.Encoding.UTF8;//郵件正文是Html編碼m_Mail.IsBodyHtml = true;//優(yōu)先級m_Mail.Priority = System.Net.Mail.MailPriority.High;//添加附件,可以添加多個//m_Mail.Attachments.Add(new Attachment("f:\\1.txt"));//密件抄送收件人m_Mail.Bcc.Add(Address);//抄送收件人m_Mail.CC.Add(Address);return m_Mail;}private bool SendEmil(){SmtpClient client = new SmtpClient();//這個地方的用戶名你可以用split從發(fā)送人中截取client.Credentials = new System.Net.NetworkCredential("wawd74520", "7452088");client.Port = 25;client.Host = "smtp.tom.com";try{client.Send(Initial("1649691481@qq.com"));//ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>alert('發(fā)送成功!')</script>");SuccMsg.Add("發(fā)送郵件成功!" + "1649691481@qq.com");return true;}catch (System.Net.Mail.SmtpException ex){SuccMsg.Add("發(fā)送郵件失敗!" + "1649691481@qq.com");return false;} }
總結(jié)
以上是生活随笔為你收集整理的C#-Stmp发邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。