因云虚拟主机的25端口默认封闭,需要使用SSL加密端口(通常是465端口)来对外进行发送邮件。本文通过提供.NET、PHP和ASP样例来介绍使用SSL加密端口发送邮件的方法,其他语言的实现思路与本文介绍的方法基本相同。
下载路径:.NET源程序样例
截取部分源程序样例如下:
MailMessage mmsg = new MailMessage();
mmsg.Subject = "主题"; //邮件主题
mmsg.BodyFormat = MailFormat.Html;
mmsg.Body = "正文"; //邮件正文
mmsg.BodyEncoding = Encoding.UTF8; //正文编码
mmsg.Priority = MailPriority.High; //优先级
mmsg.From = "a***@example.com"; //发件人邮箱地址
mmsg.To = "b***@example.com"; //收件人邮箱地址
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "test01"); //用户名
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123****"); //密码
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465); //端口
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); //使用SSL
System.Web.Mail.SmtpMail.SmtpServer = "smtp.****.com"; //smtp服务器
SmtpMail.Send(mmsg);
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有