zoukankan
html css js c++ java
.net 发送邮件
Code
1
2
/**/
///
<summary>
3
///
发送邮件(多个人以,分开)
4
///
</summary>
5
///
<param name="from">
发件人
</param>
6
///
<param name="to">
收件人
</param>
7
///
<param name="title">
标题/主题
</param>
8
///
<param name="content">
信件内容
</param>
9
///
<param name="cc">
抄送人
</param>
10
///
<param name="sFileName">
文件名称
</param>
11
///
<returns></returns>
12
public
static
string
SendMail(
string
from,
string
to,
string
title,
string
content,
string
cc,
string
sFileName)
13
{
14
HttpContext context
=
HttpContext.Current;
15
string
sMsg
=
""
;
16
try
17
{
18
string
sPath
=
Global.UTDocPath
+
"
Email/
"
;
19
SmtpClient smtp
=
new
SmtpClient(
"
testEmail
"
);
20
smtp.UseDefaultCredentials
=
true
;
21
smtp.DeliveryMethod
=
SmtpDeliveryMethod.Network;
22
MailMessage msg
=
new
MailMessage(from, to, title, content);
23
if
(sFileName
!=
""
)
24
{
25
string
[] sfile
=
sFileName.Split(
new
char
[]
{
'
,
'
}
);
26
for
(
int
i
=
0
; i
<
sfile.GetLength(
0
); i
++
)
27
{
28
if
(sfile[i].Trim()
!=
""
)
29
{
30
System.Net.Mail.Attachment attachment
=
new
System.Net.Mail.Attachment(context.Server.MapPath(sPath
+
"
/
"
+
sfile[i].Trim()));
31
msg.Attachments.Add(attachment);
32
}
33
}
34
35
}
36
37
msg.BodyEncoding
=
System.Text.Encoding.UTF8;
38
msg.SubjectEncoding
=
System.Text.Encoding.UTF8;
39
if
(cc
!=
""
)
40
msg.CC.Add(cc);
41
msg.IsBodyHtml
=
true
;
42
smtp.Send(msg);
43
sMsg
=
"
发送成功
"
;
44
}
45
catch
(System.Net.Mail.SmtpException ex)
46
{
47
sMsg
=
ex.Message.ToString();
48
}
49
return
sMsg;
50
}
51
查看全文
相关阅读:
Fire
Apple Tree
访问艺术馆
三角关系
字母表
折纸
旅行
单词分类
花
圆桌游戏
原文地址:https://www.cnblogs.com/goldnet/p/1515310.html
最新文章
git 使用技巧之采用别名,简化命令
6,synchronized, lock 区别
5,临界区 之 lock
native2ascii -- 编码转化工具
javap -- Java 类文件解析器
js 去除字符串空格
Js apply()使用详解 (转)
51 Nod 1678 lyk与gcd
BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's
POJ 1469 COURSES
热门文章
RMQ 算法 学习整理
HDU 1151 Air Raid
POJ 3041 Asteroids
HDU 1054 Strategic Game
后缀数组 救命版
洛谷 P1198 [JSOI2008]最大数
洛谷 P1270 “访问”美术馆
对峙
Road Construction
埃及分数
Copyright © 2011-2022 走看看