您的位置:首页 > 其它

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

2012-04-17 17:32 127 查看
#region 功能:实现发送邮件 1.0
class SendEmail_1
{
public static void Sendmail()
{
SmtpClient smtp = new SmtpClient("smtp.163.com");
//发件人的地址
MailAddress from = new MailAddress("abc@163.com", "itmaper", Encoding.UTF8);

//不使用默认的凭据发送
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("adc@163.com", "password");

//收件人的地址
MailAddress to = new MailAddress("1065359365@qq.com");
//邮件信息
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: