调用DEMO

      var currUser = new List<string> { "123@qq.com" , "123@qq.com" , "123@qq.com" };// 单个
var title = "test";
var content = "hello word";
mh.SendSMTPEMail(currUser, title, content);

  

方法:

    public class MailHelper
{
private string emailAcount = ConfigurationManager.AppSettings["EmailAcount"];
private string emailPassword = ConfigurationManager.AppSettings["EmailPassword"];
private string emailSmart = ConfigurationManager.AppSettings["EmailSmart"]; public void SendSMTPEMail(string strto, string strSubject, string strBody)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(emailSmart);
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(emailAcount, emailPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(emailAcount, strto, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true; //使用文件路径发送附件
//AlternateView item = new AlternateView(@"D:\\软件\\(软电话)eyebeam1.5.rar", "application/x-rar-compressed");
//message.AlternateViews.Add(item);
//message.AlternateViews.Dispose(); //使用Stream发送附件
//Attachment letter = new Attachment(FileUploadLetter.FileContent, FileUploadLetter.PostedFile.ContentType);
//letter.ContentDisposition.Inline = true;
//letter.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
////inline.ContentId = "1";
//letter.ContentType.MediaType = FileUploadLetter.PostedFile.ContentType;
//letter.ContentType.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
//letter.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
//message.Attachments.Add(letter);
//message.Attachments.Dispose(); client.Send(message);
} public void SendSMTPEMail(List<string> strto, string strSubject, string strBody)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(emailSmart);
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(emailAcount, emailPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network; foreach (var str in strto)
{
try
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(emailAcount, str, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}
catch
{ } } }
}

  

1.补充知识

(1)POP3和SMTP服务器是什么?

简单点来说:POP3 用于接收电子邮件 ,SMTP 用于发送电子邮件。

(1)POP3具体指什么?

POP3(Post Office Protocol 3)即邮局协议的第3个版本,它是规定个人计算机如何连接到互联网上的邮件服务器进行收发邮件的协议。它是因特网电子邮件的第一个离线协议标准,POP3协议允许用户从服务器上把邮件存储到本地主机(即自己的计算机)上,同时根据客户端的操作删除或保存在邮件服务器上的邮件,而POP3服务器则是遵循POP3协议的接收邮件服务器,用来接收电子邮件的。POP3协议是TCP/IP协议族中的一员,,由RFC 1939 定义

(2)SMTP具体是指什么?

SMTP的全称是"Simple Mail Transfer Protocol",即简单邮件传输协议。它是一组用于从源地址到目的地址传输邮件的规范,通过它来控制邮件的中转方式。SMTP 协议属于 TCP/IP 协议簇,它帮助每台计算机在发送或中转信件时找到下一个目的地。SMTP 服务器就是遵循 SMTP 协议的发送邮件服务器。

2.System.Net.Mail

使用ASP.NET发送电子邮件,需要引用System.Net.Mail命名空间。System.Net.Mail 命名空间包含用于将电子邮件发送到简单邮件传输协议 (SMTP) 服务器进行传送的类。

(1)命名空间下有三个比较主要的类:

MailMessage:提供属性和方法来创建一个邮件消息对象,即邮件内容。

Attachment:提供属性和方法来创建一个邮件附件对象,即邮件附件。

SmtpClient:将电子邮件传输到您指定用于邮件传送的 SMTP 主机。

(2)MailMessage类:

From:发送邮件的地址 
To:接收邮件的地址 
Subject:邮件的标题 
Priority:邮件的优先级(分别为为High,Low,Normal) 
Attachments:电子邮件的数据的附件集合
Bcc:密送地址 
Cc:抄送地址 
Body:邮件正文
SubjectEncoding:电子邮件的主题内容使用的编码

IsBodyHtml:邮件正文是否为 Html 格式的值

详细参考:MailMessage

(3)Attachment类:

详细参考:Attachment

(4)SmtpClient类:

DeliveryMethod:指定如何处理待发的电子邮件

Host:SMTP 事务的主机的名称或 IP 地址

Credentials:设置用于验证发件人身份的凭据

详细参考:SmtpClient

 3.ASP.NET发送邮件两种方式

(1)通过邮件服务提供商的SMTP来发送邮件

首先需要注册对应服务提供商免费邮箱,因为你要使用邮件服务提供商的SMTP,他们需要对身份进行验证,这样可以避免产生大量的垃圾邮件。

有三个是重要的信息:SMTP服务器、用户名、密码。从网上收集了几个类,可以参考下。

Net SMTP QQ 发送邮件的更多相关文章

  1. python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件

    python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件 使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPA ...

  2. 阿里云服务器发送邮件:Connection could not be established with host smtp.qq.com [Connection timed out #110]

    阿里云服务器发送邮件:Connection could not be established with host smtp.qq.com [Connection timed out #110] 一.总 ...

  3. python使用smtplib库和smtp.qq.com邮件服务器发送邮件(转)

    使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPAuthenticationError 主要的原因就是口令和帐号信息不对,这里我们 ...

  4. python使用smtplib库和smtp.qq.com邮件服务器发送邮件

    使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPAuthenticationError 主要的原因就是口令和帐号信息不对,这里我们 ...

  5. wordpress配置SMTP服务发送邮件(qq邮箱)

    wordpress有一个注册功能,填了用户名和邮箱后,会收到一封邮件,邮件里有一个链接,点击该链接可以获得密码和修改密码.但是,最开始,你会发现,等半天都没有收到邮件,再等到猴年马月也不会收到. 但是 ...

  6. Could not connect to SMTP host: smtp.qq.com, port: 465, response: -1 SpringBoot发送邮件

    解决方案 换端口 QQ邮箱可以把端口换成587 设置属性 spring.mail.properties.mail.smtp.ssl.enable=true 原因 465端口是为SMTPS(SMTP-o ...

  7. C#使用简单邮件传输协议(SMTP)发送邮件

    1.首先引入命名空间: using System.Net.Mail; 2.定义邮件配置类: public class EmailServiceConfig { /// <summary> ...

  8. python smtp模块发送邮件

    应用场景: 在服务器上设置的告警参数被触发后,通常是发送手机短信或者邮件通知,本例就以发送邮件为例,手机怎么收邮件呢?以qq邮箱为例,在手机端安装qq邮箱app,触发邮件后,手机也能及时查看了 代码展 ...

  9. CentOS7配置mailx使用外部smtp服务器发送邮件

    转自huskiesir的博客: 发送邮件的两种方式: 1.连接现成的smtp服务器去发送(此方法比较简单,直接利用现有的smtp服务器比如qq.新浪.网易等邮箱,只需要直接配置mail.rc文件即可实 ...

随机推荐

  1. [LeetCode] 747. Largest Number At Least Twice of Others_Easy

    In a given integer array nums, there is always exactly one largest element. Find whether the largest ...

  2. NetBeans issues and solutions.(build.xml and debug multiple projects)

    Copy a directory to another directory when building the .jar in NetBeans in the build.xml file. Solu ...

  3. 原生js---ajax的封装插件.js---(对get和post做了兼容)

    function ajax(method,url,data,fn){ // 1.创建对象 var xhr=null; try{ xhr=new XMLHttpRequest(); }catch(e){ ...

  4. 漏洞复现:Struts2 远程代码执行漏洞(S2-033)

    docker pull medicean/vulapps:s_struts2_s2-033 docker run -d -p 80:8080 medicean/vulapps:s_struts2_s2 ...

  5. MyBatis基础入门《十 一》修改数据

    MyBatis基础入门<十 一>修改数据 实体类: 接口类: xml文件: 测试类: 测试结果: 数据库: 如有问题,欢迎纠正!!! 如有转载,请标明源处:https://www.cnbl ...

  6. linux 中的screen出现cannot find terminfo entry 的错误

    事情的起因: 本地使用urxvt terminal ,使用ssh方式远程登录服务器,远程在服务器端执行screen命令,然后就出现了cannot find terminfo entry的错误. 解决方 ...

  7. python 爬起点目录

    #目标:书名,简介,作者,字数 #首先确定源代码的列表 import urllib.request import re from bs4 import BeautifulSoup import ran ...

  8. POJ1944 Fiber Communications (USACO 2002 February)

    Fiber Communications 总时间限制:  1000ms 内存限制:  65536kB 描述 Farmer John wants to connect his N (1 <= N ...

  9. 爬取小说 spider

    1.代码: # -*- coding:UTF- -*- from bs4 import BeautifulSoup import requests, sys """ 类说 ...

  10. 20165305 苏振龙《Java程序设计》第八周课上测试补做

    1. 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入world.sql,提交导入成功截图 2. ...