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 ...
随机推荐
- BZOJ1012 [JSOI2008]最大数 线段树
题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:LLL不超过当前数列的长度.(L> ...
- [HAOI2006]聪明的猴子 BZOJ 2429 Kruskal
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...
- Could not get lock /var/lib/apt/lists/lock
执行: apt-get update 出现 Could not get lock /var/lib/apt/lists/lock 解决办法: 查询与apt相关的进程 ps -e | grep apt ...
- 浏览器端 禁止 html 使用后退 或者替换后退功能..
知乎大佬的代码: 作者:独夜行 链接:https://www.zhihu.com/question/40511430/answer/166467343 来源:知乎 著作权归作者所有.商业转载请联系作者 ...
- git 如何删除远程提交方法总结
今天不小心把代码提到主分支了,虽然改动只有一点点,但感觉asdasdasdsadd(要被骂死) 怎么样才能删除掉远程的分支呢. 假设我们有提交 commit commit commit 手残把3提交错 ...
- 使用PHP并发执行任务–curl_multi应用
使用PHP并发执行任务–curl_multi应用 原网址:http://lampblog.org/category/phpdev
- PostgreSQL精简命令:
dos命令行连接PostgreSQL: . 接入PostgreSQL数据库: psql -h IP地址 -p 端口 -U 用户名 -d 数据库名 . 输入数据库密码 C:\Users\admin\De ...
- python练习七十:图片生成
题目:使用python生成类似于下图的字母验证码图片 实现代码: from PIL import Image,ImageFont,ImageDraw,ImageFilter import random ...
- POJ 2570 Fiber Network
Description Several startup companies have decided to build a better Internet, called the "Fibe ...
- Root用户让其他用户运行某程序
这里以启动tomcat为例 1.安装tomcat不介绍了,自己百度 2.测试能否使用,略 3.创建tomcat用户 useradd tomcat -s /sbin/nologin 创建tomcat,禁 ...