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
查看全文
相关阅读:
Troubleshooting FIM: (No Display Name) in FIM Portal
FIM2010同步用户
Problem with WinRM on Exchange 2013 Management Shell and Exchange Toolbox on a new exchange 2013 with CAFE and BE on single server installation
SAML : A SAML stack
Flutter-使用Custompaint绘制一个圆圈进度条
Flutter-自绘组件CustomPaint
AnimatedSwitcher
入职一个月
flutter--static关键字
Flutter-变量初始化问题
原文地址:https://www.cnblogs.com/goldnet/p/1515310.html
最新文章
人月神话阅读笔记01
每周总结
第二阶段站立会议7
构建之法阅读笔记05
Spring容器技术内幕之BeanWrapper类介绍
Sring容器技术内幕之InstantiationStrategy类介绍
Spring容器技术内幕之BeanDefinition类介绍
Spring容器技术内幕之内部工作机制
ApplicationContext中Bean的生命周期
BeanFactory中Bean的生命周期
热门文章
BeanFactory和ApplicationContext的简单介绍
类装载器-ClassLoader
Angular和Spring Boot一起做个项目
Spring MVC中自定义拦截器的简单示例
Windows TCP连接数限制解决
Httplistener Access Denied
Hadoop出现 native snappy library not available: SnappyCompressor has not been loaded的解决办法
YARN的内存和CPU配置
disable-the-loopback-check-for-specific-host-names-on-all-sharepoint-web-and-application-servers/
Creating Custom Connector Sending Claims with SharePoint 2013
Copyright © 2011-2022 走看看