所以,我不用25端口了,改465了,但是.net的邮箱组件貌似利用465发不出去邮件,我也懒得去找问题了,直接换一个cdo组件来。
可以引用的COM组件列表,发现里面有一个名为Microsoft CDO For Exchange 2000 Library的COM组件,就是这个
// 设置发送方的邮件信息,例如使用网易的smtp
string smtpServer = txt_smtp.Text.Trim(); //SMTP服务器 smtp.163.com
string mailFrom = txt_form.Text.Trim(); //登陆用户名 发件邮箱
string userPassword = txt_formpass.Text.Trim();//登陆密码 网易邮箱授权码 qq邮箱独立密码
string mailTo = txt_to.Text.Trim();//发送给谁 123@qq.com
string mailProt = txt_prot.Text.Trim();//smtp端口 465
string mailSubject = txt_proj.Text.Trim();//主题 标题 邮件标题
string mailContent = txt_tocont.Text.Trim();//发送内容 随便定义
string mailFromname = txt_fromnam.Text.Trim();//谁发送的 某某某牛逼公司
try
{
CDO.Message oMsg = new CDO.Message();
Configuration conf = new ConfigurationClass();
conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value = CdoSendUsing.cdoSendUsingPort;
conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
conf.Fields[CdoConfiguration.cdoSMTPUseSSL].Value = true;
conf.Fields[CdoConfiguration.cdoSMTPServer].Value = smtpServer;//必填,而且要真实可用
conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value = mailProt;//465特有
conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value = "<" + mailFrom + ">";
conf.Fields[CdoConfiguration.cdoSendUserName].Value = mailFrom;//真实的邮件地址
conf.Fields[CdoConfiguration.cdoSendPassword].Value = userPassword; //为邮箱密码,必须真实
conf.Fields.Update();
oMsg.Configuration = conf;
oMsg.HTMLBody = mailContent;
oMsg.Subject = mailSubject;
oMsg.From =$"({mailFromname}){mailFrom}";
oMsg.To = mailTo;
oMsg.AddAttachment(AppDomain.CurrentDomain.BaseDirectory+"/Comm/附件.xlsx","","");
oMsg.Send();
MessageBox.Show("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show($"发送失败:{ex.Message}");
}
川公网安备 51010702003150号
留下您的脚步
最近评论