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. 第2章 Python基础语法--Hello python

    第2章 基础语法 2.1 基本介绍 2.1.1 Hello python 每个语言的开始都是从”HelloWorld”开始的,我们也不例外.打开已经安装好的Python编译环境,至于Python如何安 ...

  2. shell学习之用户管理和文件属性

    1.组和用户的添加 添加组: groupadd [-g gid [-o]] [-r] [-f] group 示例: groupadd -g testgoup1 #添加组testgroup1,同时指定g ...

  3. qstring.h赏析

    https://github.com/qtproject/qtbase/blob/dev/src/corelib/tools/qstring.h C:\Qt\Qt5.3.2_min\5.3\mingw ...

  4. 基于visual Studio2013解决C语言竞赛题之0305显示星期

     题目 解决代码及点评 这道题锻炼我们switch分支语句,对于条件太多时,用if符合条件分支是比较复杂的 可以使用switch代替 //5. 读入1到7之间的某个数,输出表示一星期中相应的 // ...

  5. Visual c++例子,可不使用常规的对话框资源模板的情况下,动态创建对话框的方法

    详细说明:Visual c++例子,可不使用常规的对话框资源模板的情况下,动态创建对话框的方法.该方法可以在运行时在内存中直接建立对话框资源,使用起来更为灵活.适用于多个开发项目共享有界面的公用程序模 ...

  6. 雪佛兰Suburban_百度百科

    雪佛兰Suburban_百度百科 雪佛兰Suburban

  7. css中的定位

    上一篇博客,我大概介绍了下浮动的使用及行为.其实在整个文档布局中,定位也对我们整个的页面排版有非常好的帮助,当然前提是使用得当. 一.定位分类: a.静态定位  position:static;   ...

  8. 内核必看: spinlock、 mutex 以及 semaphore

    linux 内核的几种锁介绍 http://wenku.baidu.com/link?url=RdvuOpN3RPiC5aY0fKi2Xqw2MyTnpZwZbE07JriN7raJ_L6Ss8Ru1 ...

  9. 4.1 技术原理 & 4.2 键盘过滤框架

    4.1 技术原理 & 4.2 键盘过滤框架 4.1 预备知识 符号链接:符号链接其实就是一个“别名”.可以用一个不同的名字来代表一个设备对象(实际上),符号链接可以指向任何有名字的对象. Zw ...

  10. ajax 基础实例

      优点:使用ajax读取数据文件,不需要刷新页面就能取出文件数据 目  录 1.0 基于ajax请求的理论支持 1.1 js 实现jquray中 ajax请求功能 基于ajax请求的理论支持 < ...