1.实例:从qq邮箱 发送到其他地址的邮箱

>telnet smtp.qq.com 25

>helo qq.com

>auth login

>NzI3MTU0MTg3QHFxLmNvbQ== (邮箱名的base64编码  http://tool.chinaz.com/Tools/base64.aspx)

>。。。。。。。。。。。。。。。。。(邮箱密码的base64编码)

>mail from:727154187@qq.com

>rcpt to:jimei@outlook.com

>Data

From:727154187@qq.com

TO:jimei@outlook.com

Subject:test mail

.     (注意最后以'.'结束)

[注]查找smtp 地址的命令: nslookup -type=mx [域名]

2.常用命令:

参数
作用
HELO
使用标准的SMTP,向服务器标识用户身份。发送者能进行欺骗,但一般情况下服务器都能检测到
EHLO
使用ESMTP,向服务器标识用户身份。发送者能进行欺骗,但一般情况下服务器都能检测到。
STARTTLS
启用TLS
MAIL FROM
命令中指定的地址是发件人地址
RCPT TO
标识单个的邮件接收人;可有多个 RCPT TO;常在 MAIL 命令后面
DATA
在单个或多个 RCPT 命令后,表示所有的邮件接收人已标识,并初始化数据传输,以CRLF.CRLF 结束
VRFY
用于验证指定的用户/邮箱是否存在;由于安全方面的原因,服务器常禁止此命令
EXPN
验证给定的邮箱列表是否存在,扩充邮箱列表,也常被禁用
HELP
查询服务器支持什么命令
NOOP
无操作,服务器响应 250 OK
RSET
重置会话,当前传输被取消,服务器响应 250 OK
QUIT
结束会话

3.常见错误码:

421 Service not available, closing transmission channel (This may be a reply to any command if the service knows it must shut down)
450 Requested mail action not taken: mailbox unavailable (E.g., mailbox busy)
451 Requested action aborted: local error in processing
452 Requested action not taken: insufficient system storage
500 Syntax error, command unrecognized (This may include errors such as command line too long)
501 Syntax error in parameters or arguments
502 Command not implemented
503 Bad sequence of commands
504 Command parameter not implemented
550 Requested action not taken: mailbox unavailable (E.g., mailbox not found, no access)
551 User not local; please try
552 Requested mail action aborted: exceeded storage allocation
553 Requested action not taken: mailbox name not allowed (E.g., mailbox syntax incorrect)
554 Transaction failedThe other codes that provide you with helpful information about what’s happening with your messages are:
211 System status, or system help reply
214 Help message (Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful
only to the human user)
220 Service ready
221 Service closing transmission channel
250 Requested mail action okay, completed
251 User not local; will forward to
354 Start mail input; end with . (a dot)
‘*************************  
  ‘*   邮件服务返回代码含义  
  ‘*   500   格式错误,命令不可识别(此错误也包括命令行过长)  
  ‘*   501   参数格式错误  
  ‘*   502   命令不可实现  
  ‘*   503   错误的命令序列  
  ‘*   504   命令参数不可实现  
  ‘*   211   系统状态或系统帮助响应  
  ‘*   214   帮助信息  
  ‘*   220   服务就绪  
  ‘*   221   服务关闭传输信道  
  ‘*   421   服务未就绪,关闭传输信道(当必须关闭时,此应答可以作为对任何命令的响应)  
  ‘*   250   要求的邮件操作完成  
  ‘*   251   用户非本地,将转发向  
  ‘*   450   要求的邮件操作未完成,邮箱不可用(例如,邮箱忙)  
  ‘*   550   要求的邮件操作未完成,邮箱不可用(例如,邮箱未找到,或不可访问)  
  ‘*   451   放弃要求的操作;处理过程中出错  
  ‘*   551   用户非本地,请尝试  
  ‘*   452   系统存储不足,要求的操作未执行  
  ‘*   552   过量的存储分配,要求的操作未执行  
  ‘*   553   邮箱名不可用,要求的操作未执行(例如邮箱格式错误)  
  ‘*   354   开始邮件输入,以.结束  
  ‘*   554   操作失败  
  ‘*   535   用户验证失败  
  ‘*   235   用户验证成功  
  ‘*   334   等待用户输入验证信息

 <%@ WebHandler Language="C#" Class="SendMailHandler" %>

 using System;
using System.Linq;
using System.Web;
using System.Web.SessionState; using System.Collections.Generic;
using System.Web.Script.Serialization; using System.Text.RegularExpressions;
using System.Net;
using System.Net.Mail; public class SendMailHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
JavaScriptSerializer ser = new JavaScriptSerializer();
var form=context.Request.Form;
string email =form["email"]??""; bool status=false;
string msg="";
string log="";
try
{ var smtpSetting=new Smtp
{
Port= ,
EnableSsl=false ,
Host="smtp.qq.com" ,
Password="******" ,
UserName="727154187@qq.com" ,
From="727154187@qq.com" ,
To=new string[] { "jimei@outlook.com" }
}; Regex reg = new Regex(@"^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"); if(smtpSetting!=null && !string.IsNullOrEmpty(email) && reg.IsMatch(email))
{ var template=@"<div>
<p><b>Gender:</b> <span>$$gender$$</span></p>
<p><b>Name:</b> <span>$$name$$</span></p>
<p><b>Email:</b> <span>$$email$$</span></p>
<p><b>Topic:</b> <span>$$topic$$</span></p>
<p><b>Content:</b> <span>$$content$$</span></p></div>";
var g=form["gender"]??""; template=template.Replace("$$gender$$" ,g==""?"male":"female");
template=template.Replace("$$name$$" , form["name"]??"");
template=template.Replace("$$email$$" , form["email"]??"");
template=template.Replace("$$topic$$" , form["topic"]??"");
template=template.Replace("$$content$$" ,form["content"]??""); status=SendEmail(smtpSetting , "ContactUs" , template,out log); }
}
catch(Exception e)
{
msg=e.Message;
status=false;
}
var objRtn = new { result=status.ToString(),Msg=msg,Log=log};
context.Response.Write(ser.Serialize(objRtn));
context.Response.End();
} private bool SendEmail(Smtp smtpSetting,string subject , string body,out string result)
{
SmtpClient smtpClient = new SmtpClient();
result="";
if(smtpSetting != null)
{
smtpClient.Host = smtpSetting.Host;
smtpClient.Port = smtpSetting.Port;
smtpClient.EnableSsl = smtpSetting.EnableSsl; if(!String.IsNullOrEmpty(smtpSetting.UserName) && !String.IsNullOrEmpty(smtpSetting.Password))
{
try
{
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(smtpSetting.UserName , smtpSetting.Password); if(!string.IsNullOrEmpty(smtpSetting.From) && smtpSetting.To!=null && smtpSetting.To.Length>)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(smtpSetting.From , smtpSetting.From);
foreach(string item in smtpSetting.To)
{
message.To.Add(new MailAddress(item));
}
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = true; smtpClient.Send(message);
return true;
}
}
catch(Exception e)
{
result=e.Message;
return false;
} } }
return false;
} public bool IsReusable
{
get
{
return false;
}
}
}

SendMail

     public   class Smtp
{
public Smtp() { } public bool EnableSsl { get; set; }
public string From { get; set; }
public string Host { get; set; }
public string Password { get; set; }
public int Port { get; set; }
public string[] To { get; set; }
public string UserName { get; set; }
}

Smtp

SMTP命令 发送邮件 DOS命令的更多相关文章

  1. Windows命令行(DOS命令)教程-8 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_7.html

    15. pass [功能] 设定DOS寻找.COM..EXE..BAT文件的所在目录 [格式] path=[[drive:]path[;-]]或path [说明] 只打path没有参数时,只显示环境变 ...

  2. Windows命令行(DOS命令)教程-7 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_6.html

    11. deltree [功能] 删除目录树 [格式] [C:][path]DELTREE [C1:][path1] [[C2:][path2] […]] [说明] 这个命令将整个指定目录树全部消灭, ...

  3. Windows命令行(DOS命令)教程-3(转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_2.html

    五.常用命令 DOS命令总共大约有一百个(包括文本编辑.查杀病毒.配置文件.批处理等),我们这里详细介绍二十个常用的DOS命令. 先介绍一下通配符的概念. 通配符*和? *表示一个字符串 ?只代表一个 ...

  4. Windows命令行(DOS命令)教程–2 (转载) http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_1.html

    二.符号约定 为了便于说明格式,这里我们使用了一些符号约定,它们是通用的: C: 盘符 Path 路径 Filename 文件名 .ext 扩展名 Filespec 文件标识符 [ ] 方括号中的项目 ...

  5. Windows命令行(DOS命令)教程 -1 (转载) http://www.pconline.com.cn/pcedu/rookie/basic/10111/15325.html

    一.命令行简介 命令行就是在Windows操作系统中打开DOS窗口,以字符串的形式执行Windows管理程序. 在这里,先解释什么是DOS? DOS--Disk Operation System 磁盘 ...

  6. Windows命令行(DOS命令)教程

    一.命令行简介 命令行就是在Windows操作系统中打开DOS窗口,以字符串的形式执行Windows管理程序. 在这里,先解释什么是DOS? DOS——Disk Operation System 磁盘 ...

  7. 常用windows命令和Dos命令

    Windows常用快捷键 Ctrl + C :复制 Ctrl + V :粘贴 Ctrl + X :剪切 Ctrl + A :全选 Ctrl + Z :撤销(做错了后退一步) Ctrl + Y :向前一 ...

  8. Windows命令行(DOS命令)教程-6 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_5.html

    8. type [功能] 在屏幕上显示文本文件内容命令 [格式] type [C:][path]filename.ext [说明] type命令用来在屏幕上快速.简便地显示文本文件的内容,扩展名为TX ...

  9. Windows命令行(DOS命令)教程-5 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_4.html

    5. copy copy在英文中是复制的意思 [功能] 复制一个或一组文件到指定的磁盘或目录中 [格式] copy [C:][path][filename.ext] [C:][path]filenam ...

随机推荐

  1. Oracle 传参错误

    错误:ORA-01008: 并非所有变量都已绑定 报错的SQL:UPDATE RES_AUTHORITY SET                                  F_APPLYER= ...

  2. Python:爬取乌云厂商列表,使用BeautifulSoup解析

    在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...

  3. cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(二)

    在了解地图的初始化和加载之前,我们先了解下mario的地图. 用tiled工具打开mario地图 从地图中可以看到,mario的地图有很多层构成: objects层:怪物,会动的怪物 coin层:金币 ...

  4. Redhat 5.8系统安装R语言作Arima模型预测

    请见Github博客:http://wuxichen.github.io/Myblog/timeseries/2014/09/02/RJavaonLinux.html

  5. 商业模式画布及应用 - MBA智库文档

    商业模式画布及应用 - MBA智库文档 商业模式画布及应用

  6. [Android学习笔记5]四大应用组件之一:Service 下

    绑定方式的Service使用 在实现绑定服务时,最重要的是定义onBind()回调方法返回的接口,有三种方式: 1. 继承Binder类 2. 使用Messenger 3. 使用AIDL 这里对1,2 ...

  7. C#实现多人语音聊天

    在上一篇文章 实现一个简单的语音聊天室(多人语音聊天系统)中,我用C#实现了一个简单的语音聊天室,并给出了源代码下载.尽管有源代码,可是非常多朋友反映,理解起来还是有些模糊.不够清楚.如今想来,是由于 ...

  8. AlertDialog具体解释

    对话框介绍与演示样例         对话框在程序中不是必备的,可是用好对话框能对我们编写的应用增色不少.採用对话框能够大大添加应用的友好性.比較经常使用的背景是:用户登陆.网络正在下载.下载成功或者 ...

  9. Oracle自带的exception

    存储过程中自带的exception: --查询人员资料历史 BEGIN SELECT * INTO Po_Sac01 FROM Sac01 WHERE Aac001 = Pi_Aac001 ); EX ...

  10. Chapter 3.单一职责原则

    单一职责原则:就一个类而言,应该仅有一个引起它变化的原因. 如果一个类承担的职责过多,就等于把这些职责耦合在一起,一个职责的变化可能会削弱或者抑制这个类完成其他职责的能力,就等于把这些职责耦合在一起, ...