-
C#教程之C#教程之阿里云服务器不能发邮件禁用25端口的三(2)
第三种方法:
这个方式是官方给的,主要是通过System.Web.Mail.MailMessage来实现发送,大家把这个方法放到自己的项目里面调用就好
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/// <summary> /// 通过System.Web.Mail.MailMessage去发送,可以不被阿里云限制25端口的使用 /// 暂时一般都用465端口 /// </summary> /// <param name="smtpserver">SMTP服务,譬如:smtp.126.com</param> /// <param name="userName">发件箱</param> /// <param name="pwd">密码</param> /// <param name="nickName">昵称</param> /// <param name="strfrom">发件箱</param> /// <param name="strto">收件箱</param> /// <param name="MessageSubject">主题</param> /// <param name="MessageBody">内容</param> /// <param name="SUpFile">附件</param> /// <param name="port">端口</param> /// <param name="enablessl">SSL加密</param> /// <returns></returns> public static bool SendWebEmail( string smtpserver, string userName, string pwd, string nickName, string strfrom, string strto, string MessageSubject, string MessageBody, string SUpFile, int port, int enablessl = 0) { System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage(); //邮件主题 mmsg.Subject = MessageSubject; mmsg.BodyFormat = System.Web.Mail.MailFormat.Html; //邮件正文 mmsg.Body = MessageBody; //正文编码 mmsg.BodyEncoding = Encoding.UTF8; //优先级 mmsg.Priority = System.Web.Mail.MailPriority.High; System.Web.Mail.MailAttachment data = null ; if (SUpFile != "" ) { SUpFile = HttpContext.Current.Server.MapPath(SUpFile); //获得附件在本地地址 System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(SUpFile); //create the attachment mmsg.Attachments.Add(attachment); //add the attachment } //发件者邮箱地址 mmsg.From = string .Format( "\"{0}\"<{1}>" ,nickName, strfrom); //收件人收箱地址 mmsg.To = strto; mmsg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" , "1" ); //用户名 mmsg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername" , userName); //密码 mmsg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword" , pwd); //端口 mmsg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" , port); //使用SSL mmsg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" , (enablessl == 1 ? "true" : "false" )); //Smtp服务器 System.Web.Mail.SmtpMail.SmtpServer = smtpserver; try { System.Web.Mail.SmtpMail.Send(mmsg); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return false ; } return true ; } |
栏目列表
最新更新
如何使用OS模块中的stat方法
Python os 模块
seek() 方法
python打开文件实例1
Python写入文件
什么是流?
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
access教程之Access简介
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能