Csharp: Send Email
/// <summary>
/// 發送郵件
/// 塗聚文
/// 20130816
/// </summary>
/// <param name="to">收件人</param>
/// <param name="toName">收件人姓名</param>
/// <param name="subject">標題名</param>
/// <param name="body">內容</param>
/// <returns></returns>
public bool SendMailMessage(string to, string toName, string subject, string body)
{
bool re = false;
try
{
int id = 1;
string bcc="463588883@qq.com";
string bccName = "geovindu";
string cc = string.Empty;
string ccDisName = string.Empty; vipSetMailHostInfo = vipSetMailHostBLL.SelectVipSetMailHost(id); // Instantiate a new instance of MailMessage
MailMessage mMailMessage = new MailMessage(); // Set the sender address of the mail message
mMailMessage.From = new MailAddress(vipSetMailHostInfo.SmtpUser, vipSetMailHostInfo.SmtpName);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to, toName)); //電子郵件,顯示名稱 //發送郵件,可以是集合列表 // Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{
// Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc, bccName));//密抄郵件
}
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
// Set the CC address of the mail message
mMailMessage.CC.Add(new MailAddress(cc, ccDisName)); //抄送郵件
} // Set the subject of the mail message
mMailMessage.ReplyTo = new MailAddress("vip@dupcit.com", "VIP客戶"); //回復信郵 //mMailMessage.ReplyTo = "VIP";
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body; // Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
mMailMessage.BodyEncoding = System.Text.Encoding.UTF8;// // Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal; // Instantiate a new instance of SmtpClient
// SmtpClient mSmtpClient = new SmtpClient();
SmtpClient SmtpServer = new SmtpClient(vipSetMailHostInfo.SmtpServer);
SmtpServer.Credentials = new NetworkCredential(vipSetMailHostInfo.SmtpUser, vipSetMailHostInfo.SmtpPasswor);
SmtpServer.Port = 25;
SmtpServer.EnableSsl = false;
// Send the mail message
SmtpServer.Send(mMailMessage);
re = true;
}
catch (Exception ex)
{
ex.Message.ToString();
re = false; }
return re;
}
Csharp: Send Email的更多相关文章
- Try to write a script to send e-mail but failed
#-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...
- python auto send email
/*************************************************************************** * python auto send emai ...
- Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email
Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email. (文档 I ...
- Send Email in Robot Framework Python Using Gmail
转载自:http://seleniummaster.com/sitecontent/index.php/selenium-robot-framework-menu/selenium-robot-fra ...
- 5 Ways to Send Email From Linux Command Line
https://tecadmin.net/ways-to-send-email-from-linux-command-line/ We all know the importance of email ...
- [476] Database Mail is not enabled for agent notifications. Cannot send e-mail to
配置完DB Mail后JOB的的通知邮件不能发送,日志报错476] Database Mail is not enabled for agent notifications. Cannot send ...
- Send email alert from Performance Monitor using PowerShell script (检测windows服务器的cpu 硬盘 服务等性能,发email的方法) -摘自网络
I have created an alert in Performance Monitor (Windows Server 2008 R2) that should be triggered whe ...
- Send Email
private string SendEmail(string mailTo, string body, ref int sendresult) { string errorEmailAddress ...
- .Net Core Send Email
1.安装Nuget包MailKit,引用命名空间. using MailKit.Net.Smtp; using MimeKit; 注意:引用MailKit对应最新版本 2.定义收发地址和标题 Mime ...
随机推荐
- JavaScript学习笔记——3.对象
JavaScript 对象 - 创建对象 1- var obj = new Object(); 2- var obj = {}; *例子:var person = {Name:"Hack&q ...
- [转]An STL compliant sorted vector-源码示例
原文地址:http://www.codeproject.com/Articles/3217/An-STL-compliant-sorted-vector 最近在看sorted vectored的一些东 ...
- iOS APP日志写入文件(日志收集)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- WinForm 修改App.config不起作用(但是调试没有异常)
修改Bin下的.exe.config文件,就能达到效果了. appconfig的修改,会保留在项目中,似乎不会实时地更改到.exe.config中..
- 【算法笔记】B1001 害死人不偿命的(3n+1)猜想
1001 害死人不偿命的(3n+1)猜想 (15 分)卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复砍 ...
- 【2-SAT】【并查集】NOIp模拟题 植树方案 题解
一个类似2-SAT的思想,但是简化了很多.只需要用到并查集实现. 题目描述 企鹅国打算种一批树.所谓树,就是由$N$个结点与$N-1$条边连接而成的连通无向图.企鹅国的国王对于这些树有下列要求 ...
- C++ 构造函数与默认构造函数
构造函数:C++用于构建类的新对象时需要调用的函数,该函数无返回类型!(注意:是“无”! 不是空!(void)). 默认构造函数:未提供显式初始值时,用来穿件对象的构造函数. 以上是二者的定义,但是单 ...
- flex布局在ios8上的兼容性问题
最近在做项目时,使用到了flex布局.其他ios版本都还好,唯独在ios8上遇到了flex布局没起作用的问题.后来经过研究才发现,safari使用的是webkit内核,在ios8上需要单独加一下兼容才 ...
- CentOS7下php安装mcrypt扩展
https://blog.csdn.net/skykingf/article/details/40185405 以下步骤均为本人实际操作,可能与你的安装方法有所区别,但我会尽量排除疑惑) 大致步骤(1 ...
- [转] 你并不需要Underscore/Lodash
[From] https://segmentfault.com/a/1190000004460234 Lodash 和 Underscore 是非常优秀的当代JavaScript的工具集合框架,它们被 ...