.net阿里云发送邮件25端口不能使用

 

//原始代码

public bool Send(邮箱配置 email, string to, string subject, string body)
{
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = email.邮箱服务器;
smtp.Port = port;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential(email.邮箱账号, email.邮箱密码);
MailMessage mm = new MailMessage();
mm.Priority = MailPriority.Normal;
mm.From = new MailAddress(email.邮箱账号, email.发送邮件昵称);
mm.To.Add(to);
mm.Subject = subject;
mm.Body = body;
mm.IsBodyHtml = true;
try
{
smtp.Send(mm);
}
catch (Exception ex)
{
return false;
}

return true;
}

发布到阿里云服务器上没有用因为阿里云关掉了25端口,想使用465,但是也没有用,只能重写代码

public bool Send(邮箱配置 email, string to, string subject, string body)
{
try
{
CDO.Message oMsg = new CDO.Message();

oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 465;//设置端口
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = email.邮箱服务器;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = email.邮箱账号;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = email.邮箱账号;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = email.邮箱账号;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = email.邮箱账号;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = email.邮箱密码;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value = "true";//这一句指示是否使用ssl
oMsg.Configuration.Fields.Update();
oMsg.HTMLBody = body;

oMsg.Subject = subject;

oMsg.From =email.发送邮件昵称+"<"+ email.邮箱账号+">";
oMsg.To = to;
oMsg.Send();
}
catch (System.Net.Mail.SmtpException ex)
{
throw ex;
return false;
}
return true;
}

cod.message的引用位置: C:\Windows\System32\cdosys.dll

文章出处引用地址https://www.ie81.com/Technology/225.html?tdsourcetag=s_pcqq_aiomsg

 

转载于:https://www.cnblogs.com/liwangxing-xiaotaiye/p/10132066.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值