惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
F
Full Disclosure
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
N
News and Events Feed by Topic
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
C
Check Point Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
The Blog of Author Tim Ferriss
O
OpenAI News
V
V2EX
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security @ Cisco Blogs
C
Cisco Blogs
Security Latest
Security Latest
S
Security Affairs
V
Visual Studio Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
AWS News Blog
AWS News Blog
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
博客园_首页
U
Unit 42
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题
H
Hacker News: Front Page

博客园 - 子风

Android相关转载帖子 c++ 函数的工作原理 C和C++的存储模式 VS2005配置开发ARM c++ 虚析构函数的思考 arm-linux-g++ 下交叉编译libxml2 (转)Eclipse代码提示功能设置(Java & C/C++) linux下面eclipse的c++配置 VS2008 配置boost 用VS.NET2008打包程序遇到不可恢复的生成错误的解决方案 推荐一个原型的设计软件 Mockups For Desktop Grid++Report——推模式下填充子报表 c# 对象的创建过程 Failure sending mail - 子风 XP下IIS错误:Server Application Error css总结 asp.net缓存-数据依赖缓存 - 子风 - 博客园 .net 测试工具 利用7z来分卷压缩文件
.net 发送Email
子风 · 2010-02-09 · via 博客园 - 子风

using System.Net.Mail;
using System.Net;

发送EMail 是在这上面的命名空间下的。

见代码。最好是用异步发送,SmtpClient这个有个事件,可以表明是否发送成功。

代码

    /// <summary>
        
/// 发送Email
        
/// </summary>
        
/// <param name="toMailAddress">收件人地址</param>
        
/// <param name="isBCC">是否密件抄送</param>
        
/// <param name="ccEmails">抄送的地址集合</param>
        
/// <param name="subject">邮件的标题</param>
        
/// <param name="body">正文</param>
        
/// <param name="sendMailAddress">发送邮件的地址</param>
        
/// <param name="senMailPwd">发送邮件的密码</param>
        
/// <param name="port">端口号</param>
        
/// <param name="host">smtp事务机的主机或者IP地址</param>
        
/// <param name="attachments">附件的地址集合</param>
        
/// <returns>TRUE/FALSE</returns>
        public bool SendMail(string toMailAddress, bool isBCC,
                              
string[] ccEmails, string subject,
                              
string body, string sendMailAddress,
                              
string senMailPwd, int port, string host,
                              List
<string> attachments,string sendName)
        {
            MailMessage msg 
= new MailMessage();
            msg.To.Add(toMailAddress);
if (ccEmails != null)
            {
                
foreach (string email in ccEmails)
                {
                    
if (isBCC)
                    {
                        msg.Bcc.Add(email);
                    }
                    
else
                    {
                        msg.CC.Add(email);
                    }
                }
            }

            msg.From 

= new MailAddress(sendMailAddress, sendName, Encoding.UTF8);
            msg.Subject 
= subject;
            msg.SubjectEncoding 
= Encoding.UTF8;

            msg.Body 

= body;
            msg.BodyEncoding 
= Encoding.UTF8;

            msg.IsBodyHtml 

= false;
            msg.Priority 
= MailPriority.High;if (attachments != null)
            {
                
foreach (string attachment in attachments)
                {
                    msg.Attachments.Add(
new Attachment(attachment));
                }
            }

            SmtpClient client 

= new SmtpClient();
            client.Credentials 
= new NetworkCredential(sendMailAddress, senMailPwd);
            client.Port 
= port < 0 ? 25 : port;
            client.Host 
= host;
            
//client.Host = "124.207.241.165";
            if (port == 587)
            {
                client.EnableSsl 
= true;
            }
            
try
            {
                client.SendAsync(msg, msg);
                
return true;
            }
            
catch (Exception ex)
            {
                
return false;
            }
        }

学习,积累中......