最近因为用的发送邮件的地方,就查询了资料,总结以下几个方法

  1、利用新浪邮箱发送

  2、利用公司邮箱发送

  3、利用CDO发送,这种方式要引用Interop.ADODB.dll(http://www.nodevice.com/dll/Interop_ADODB_dll/item20357.html)和Interop.CDO.dll()两个文件

  具体代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Data; using CDO;
using ADODB;
namespace SendMailTest
{
class Program
{
static void Main(string[] args)
{
SendMail();
} public static string SendMsg()
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("date");
dt.Columns.Add("area");
dt.Columns.Add("orgnizer");
dt.Columns.Add("keyword"); for (int i = ; i < ; i++)
{
DataRow dr = dt.NewRow();
dr["name"] = "北文中心影视产权交易平台•影视项目路演季---路演项目征集" + i;
dr["date"] = "2017-06-30";
dr["area"] = "北京市 北京电影学院文创园(平房园区)" + i;
dr["orgnizer"] = "北文中心影视产权交易" + i;
dr["keyword"] = "影视" + i;
dt.Rows.Add(dr); } string MailBody = "<p style=\"font-size: 10pt\">以下内容为系统自动发送,请勿直接回复,谢谢。</p><table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" bgcolor=\"000000\" style=\"font-size: 10pt;line-height: 15px;\">";
MailBody += "<div align=\"center\">";
MailBody += "<tr>";
for (int hcol = ; hcol < dt.Columns.Count; hcol++)
{
MailBody += "<td bgcolor=\"999999\">&nbsp;&nbsp;&nbsp;";
MailBody += dt.Columns[hcol].ColumnName;
MailBody += "&nbsp;&nbsp;&nbsp;</td>";
}
MailBody += "</tr>"; for (int row = ; row < dt.Rows.Count; row++)
{
MailBody += "<tr>";
for (int col = ; col < dt.Columns.Count; col++)
{
MailBody += "<td bgcolor=\"dddddd\">&nbsp;&nbsp;&nbsp;";
MailBody += dt.Rows[row][col].ToString();
MailBody += "&nbsp;&nbsp;&nbsp;</td>";
}
MailBody += "</tr>";
}
MailBody += "</table>";
MailBody += "</div>";
return MailBody;
} public static void SendMail()
{
MailMessage msg = new MailMessage();
msg.To.Add("xxx@ctrchina.cn"); msg.CC.Add("xxxx@sina.com"); msg.From = new MailAddress("ffff@ctrchina.cn", "ffff", System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
//msg.Body = "邮件内容";//邮件内容
msg.Body = SendMsg(); msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级 SmtpClient client = new SmtpClient();
//client.Host = "smtp.ctrchina.cn";
client.Host = "210.77.136.200";
client.Port = ;
//client.EnableSsl = true;//经过ssl加密
client.Credentials = new System.Net.NetworkCredential("xxx@ctrchina.cn", "password");
object userState = msg;
try
{
//client.SendAsync(msg, userState);
client.Send(msg); }
catch (System.Net.Mail.SmtpException ex)
{
return;
}
} public static void SendSinaMail()
{
MailMessage msg = new MailMessage();
msg.To.Add("xxx@ctrchina.cn");
//msg.To.Add("xxx@sina.com"); msg.CC.Add("xxx@sina.com"); msg.From = new MailAddress("xxx@sina.com", "shao_sks", System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
//msg.Body = "邮件内容";//邮件内容
msg.Body = SendMsg(); msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级 SmtpClient client = new SmtpClient();
client.Host = "smtp.sina.com";
client.Port = ;
//client.EnableSsl = true;//经过ssl加密
client.Credentials = new System.Net.NetworkCredential("username", "password");
object userState = msg;
try
{
//client.SendAsync(msg, userState);
client.Send(msg); }
catch (System.Net.Mail.SmtpException ex)
{
return;
}
} public static void SenMail1()
{
try
{
CDO.Message oMsg = new CDO.Message(); Configuration MyConfig = new ConfigurationClass();
Fields MyFields = MyConfig.Fields;
MyFields[@"http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = ;
MyFields[@"http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = ;
MyFields[@"http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "210.77.136.200";
MyFields.Update(); oMsg.Configuration = MyConfig; oMsg.Subject = "Test SMTP2911111";
oMsg.HTMLBody = SendMsg(); oMsg.From = "shaoks@ctrchina.cn";
oMsg.To = "shaoks@ctrchina.cn"; oMsg.Send(); }
catch (Exception ex)
{
return;
}
}
}
}

C# SendMail 发送邮件的更多相关文章

  1. Linux sendmail发送邮件失败诊断案例(一)

    在新服务器上测试sendmail发送邮件时,发现邮件发送不成功,检查日志文件发现如下错误(Notice:由于涉及公司服务器,邮箱等,故下面hostname.邮箱地址等信息使用xxx代替) tail - ...

  2. Linux SendMail发送邮件失败诊断案例(二)

    Linux上Sendmail经常由于一些配置问题,导致邮件发送失败,下面整理.收集了一些邮件发送失败.异常的案例. 案例1:在新服务器上测试sendmail发送邮件时,发现邮件发送不成功,检查/var ...

  3. Linux SendMail发送邮件失败诊断案例(三)

    一Linux服务器突然发送不出邮件,检查了很多地方都没有发现异常,检查/var/log/maillog发现如下具体信息: Apr 12 00:36:04 mylinux sendmail[4685]: ...

  4. linux利用sendmail发送邮件的方法

    Linux利用sendmail发送邮件, 方法1 安装sendmail即可使用, mail -s "test" user@sohu.com bin/mail会默认使用本地sendm ...

  5. Linux SendMail发送邮件失败诊断案例(四)

    最近又碰到一起Linux下SendMail发送邮件失败的案例,邮件发送后,邮箱收不到具体邮件, 查看日志/var/log/maillog 发现有"DSN: User unknown" ...

  6. Linux简单配置SendMail发送邮件

    本文简单整理了一下如何在Linux服务器上安装.配置SendMail发送邮件的步骤,此文不是配置邮件服务器,具体测试环境为CentOS Linux release 7.2.1511 (Core) ,如 ...

  7. centos下如何使用sendmail发送邮件

    最近在实施服务端日志监控脚本,需要对异常情况发送邮件通知相关责任人,记录下centos通过sendmail发送邮件的配置过程. 一.安装sendmail与mail 1.安装sendmail:  1) ...

  8. php 使用sendmail发送邮件

    php 使用sendmail发送邮件 1.配置php.ini SMTP=smtp.163.com sendmail_from = 17760273453@163.com sendmail_path = ...

  9. Linux系统下sendmail发送邮件失败的问题

         问题是:安装完sendmail,启动服务后,发送邮件第一次发送成功,后面再次无论怎么发送都不行,换邮箱也不行.在确认我的邮件发送格式正确无误后,想到查看邮件发送日志: [root@backu ...

  10. python SendMail 发送邮件

    最近在学习python 时,用到了发送邮件的操作,通过整理总结如下: 1.普通文本邮件 普通文本邮件发送的实现,关键是要将MIMEText中_subtype设置为plain,首先导入smtplib和m ...

随机推荐

  1. Chrome Capabilities & ChromeOptions

    Capabilities & ChromeOptions Chrome Extensions Contributing Downloads Getting started Android Ch ...

  2. HDU1018 (斯特林公式)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. JAVA Eclipse 教程

    http://www.runoob.com/eclipse/eclipse-tutorial.html

  4. wait(),sleep(),notify(),join()

    wait()注意以下几点: 1)wait()是属于Object类的方法. 2)调用了wait()之后会引起当前线程处于等待状态. 3)将当前线程置入“预执行队列”中,并且在wait()所在的代码行处停 ...

  5. GIt 和 Github

    原创 by zoe.zhang        GitHub中采用的比较多得是markdown的语法,博客园里对markdown的支持感觉不是特别友好,但是为了应景,还是用了markdown来写这一篇文 ...

  6. bootstrapValidator关于verbose需要优化的地方

    开发中需要用到bootstrapValidator的配置verbose:false,达到当前验证不通过不往下在验证的效果 问题: 当前字段需要remote验证时,此配置无效,原因在于remote是异步 ...

  7. poj 1066(枚举+线段相交)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6328   Accepted: 2627 Des ...

  8. 【转】学一点Git--20分钟git快速上手

    看到一篇不错的Git的简单入门教程,转过来给自己留个底. 原文地址:http://www.cnblogs.com/shuidao/p/3535299.html 在Git如日中天的今天,不懂git都不好 ...

  9. php+mysql折线图

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  10. C++的Public.lib(Public.dll) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

    今天开始编译网游服务器,找前辈借来批处理文件,版本控制上拿下代码,库等一系列资源,尼玛啊,编译出错: Public.lib(Public.dll) : fatal error LNK1112: mod ...