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
查看全文
相关阅读:
改了信仰,”U秒英伟达,卡秒英特尔“
我的技嘉GTX970G1Gaming
入手笨球BL2710PE
买显示器的各种纠结
[转]关于液晶显示器的6bit面板、8bit面板及E-IPS
Windows API中的数据结构
C语言中函数参数传递
修改powershell字体
[知乎]学了 Python 之后,再学 Java 是不是会更容易?
Windows10上用命令行,奢侈的享受?
原文地址:https://www.cnblogs.com/goldnet/p/1515310.html
最新文章
go语言-关于文件的操作和解释
web自动化测试—selenium游览器下拉框操作
web自动化测试—selenium多窗口操作
web自动化测试—selenium操作游览器属性
软件测试需注意的事项
Django简介
web框架简介
web应用简介
jQuery介绍
Bootstrap应用
热门文章
jQuery补充
jQuery事件
DOM和BOM
JavaScript 介绍
css修饰操作(下)
MariaDB常用命令
Visual Studio 2015 OpenMP: (2) reduction
Visual Studio 2015 OpenMP: (1) 初涉江湖
AMD R9 280X详细参数汇总
试用EVGA公版GTX980
Copyright © 2011-2022 走看看