当前位置 : 主页 > 编程语言 > java >

C#使用hotmail的SMTP服务器发送邮件

来源:互联网 收集:自由互联 发布时间:2022-10-15
使用微软邮件服务器方式 1. 发送者账户为hotmail账号,SMTP服务为:smtp.office365.com 2.身份验证:hotmail账号 + 密码 client.Host = "smtp.office365.com";client.Port = 587;client.EnableSsl= true;//微软与谷歌SMTP服务


使用微软邮件服务器方式

1. 发送者账户为hotmail账号,SMTP服务为: smtp.office365.com

2.身份验证:  hotmail账号  + 密码

client.Host = "smtp.office365.com";client.Port = 587;client.EnableSsl= true;//微软与谷歌SMTP服务用SSL

 

client.Credentials = new System.Net.NetworkCredential("xxx@hotmail.com", "邮箱密码");

使用网易网易邮件服务器方式

1. 发送者账户为网易邮箱账号,SMTP服务为: smtp.163.com

2.身份验证:  网易邮箱账号  + 密码

client.Host = "smtp.163.com";client.Port = 25;client.Credentials = new System.Net.NetworkCredential("xxx@163.com", "邮箱密码");

使用微软邮件服务器发送邮件完整源码 (基于.net 6.0)

// See https://aka.ms/new-console-template for more information
using System.Net.Mail;
using System.Text;

Console.WriteLine("自动发送邮件测试:");

var mailMsg = new MailMessage();
var txtSubject = "这是一个用C#编写的邮件发送Console客户端";
var txtBody = "网狐定制,网狐二开,自由职业开发者,Linux爱者,C,C++ ,C#,LUA,GO爱好者Windows,Linux,Mac,IOS,Android平台应用与游戏开发";
//var txtFrom = "xxx@163.com";
var txtFrom = "xxx@hotmail.com";
var txtTo = "xxx@qq.com";
var txtAtta = "sqldecryptor.exe";
var mailAttachment = new Attachment(txtAtta);
mailMsg.Attachments.Add(mailAttachment);

try
{

mailMsg.From = new MailAddress(txtFrom);
mailMsg.To.Add(txtTo);
mailMsg.Subject = txtSubject;
mailMsg.SubjectEncoding = Encoding.Default;
mailMsg.Body = txtBody;
mailMsg.BodyEncoding = Encoding.Default;
mailMsg.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();
//client.Host = "smtp.163.com";
client.Host = "smtp.office365.com";
//client.Port = 25;
client.Port = 587;
client.EnableSsl= true;//微软与谷歌SMTP服务用SSL
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.Credentials = new System.Net.NetworkCredential("xxx@163.com", "密码");
client.Credentials = new System.Net.NetworkCredential("xxx@hotmail.com", "密码");
Console.WriteLine("Mail Sending ...");
client.Send(mailMsg);
Console.WriteLine("Mail Send Success!");
}
catch (Exception m) //异常处理
{
Console.WriteLine(m.Message + "\n");
Console.WriteLine(m.InnerException);
}

运行效果:

C#使用hotmail的SMTP服务器发送邮件_c#

 

上一篇:Qt左键弹出菜单演示基于QML
下一篇:没有了
网友评论