在控制台下实现简单的邮件发送1.0

#region 功能:实现发送邮件 1.0
    class SendEmail_1
    {
        public static void Sendmail()
        {
            SmtpClient smtp = new SmtpClient("smtp.163.com");
//发件人的地址 MailAddress
from = new MailAddress("[email protected]", "itmaper", Encoding.UTF8); //不使用默认的凭据发送 smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential("[email protected]", "password");
//收件人的地址 MailAddress to
= new MailAddress("[email protected]"); //邮件信息 MailMessage message = new MailMessage(from, to);
//设置邮件的主题 message.Body
= "This is a test of the mail!"; //设置主题和body时候可以发送unicode字符 string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
//Environment.NewLine当前环境下的换行符 "\r\n" message.Body
+= Environment.NewLine + someArrows; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = "test message 1" + someArrows; message.SubjectEncoding = System.Text.Encoding.UTF8; smtp.Send(message); message.Dispose(); } //此版本的无法使用Gmail的邮件服务器发送,gmial发送需要设置相关的端口和经过ssl加密 } #endregion

你可能感兴趣的:(邮件发送)