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. Linux解压缩总结

    看文件名的后缀名,不同的后缀的文件解压和压缩的命令都不一样总结如下: *.tar 用 tar –xvf 解压 *.gz 用 gzip -d或者gunzip 解压 *.tar.gz和*.tgz 用 ta ...

  2. python 字典有序无序及查找效率,hash表

    刚学python的时候认为字典是无序,通过多次插入,如di = {}, 多次di['testkey']='testvalue' 这样测试来证明无序的.后来接触到了字典查找效率这个东西,查了一下,原来字 ...

  3. Runtime.getRuntime().exec(...)使用方法

    Runtime.getRuntime().exec(...)使用方法 如果想要了解更多的信息,参阅代码里面给的链接  下面是这个正确的例子 public class RuntimeExec { /** ...

  4. 在 Azure 网站上使用 Memcached 改进 WordPress

    编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 和 Windows Azure 网站开发人员体验合作伙伴共同撰写. 您是否希望改善在 ...

  5. 【第三方SDK】百度地图实现最简单的定位功能(无地图界面)

    在近期的项目中,须要实现无地图界面的定位功能,定位用户所在的城市.因此,本篇文章,主要介绍怎样使用百度地图SDK实现无导航界面的定位功能. 1.申请百度开发人员账户 2.创建应用,获取key 例如以下 ...

  6. 编程算法 - 最长公共子序列(LCS) 代码(C)

    最长公共子序列(LCS) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 给定两个字符串s,t, 求出这两个字符串最长的公共子序列的长度. 字符 ...

  7. VIM: 解决vi/vim中粘贴时行首出现很多缩进和空格的问题

    解决vi/vim中粘贴时行首出现很多缩进和空格的问题 http://www.jbxue.com/LINUXjishu/12232.html 由于在secureCRT中会将原来的文本原封不动的按照字符串 ...

  8. C++拾遗

    1三个概念 字符串字面值是一串常量字符(是一个常量),字符串字面值常量用双引号括起来的零个或多个字符表示,为兼容C语言,C++中所有的字符串字面值都由编译器自动在末尾添加一个空字符.字符串字面值的类型 ...

  9. mysql自动备份(windows)

    许多时候,为了数据安全,我们的mysql数据库需要定期进行备份,下面介绍两种在windows下自动备份方法: 1.复制date文件夹备份 ============================ 例子 ...

  10. 简单实用的下拉菜单(CSS+jquery)

    原文 简单实用的下拉菜单(CSS+jquery) 没什么可以说的,直接上例子 html+jquery代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...