|
Linux用户常用sendmail发送电子邮件,当您看了本文后可能会改用sendEmail去发送邮件了,呵呵。
1 下载sendEmail
sendEmail有Linux和windows版本软件包,依据自己的平台选择下载好了
http://caspian.dotconf.net/menu/Software/SendEmail/
登录上边的网址找到:
Download
Official>sendEmail-v1.56.tar.gz (29kb Sep 29th, 2009) ChangelogScreen Shot Windows Download:
Free sendEmail.exe for Windows. To use simply run sendEmail.exe from a console / command line.
sendEmail-v156-notls.zip (677kb Sep 29th, 2009) No TLS support
sendEmail-v156.zip (1.4mb Sep 29th, 2009) TLS supported
RPM Package:sendEmail rpm
选择适合自己的下载好了
2 安装sendEmail
sendEmail不需要安装直接解压到某目录即可直接使用。
(Linux用户) tar -zxvf sendEmail-x-y-z.tar.gz
本文选择windows平台sendEmail软件包,下载后解压到c:\sendEmail目录下。

3 sendEmail命令帮助
sendEmail软件是命令行软件,需要在Dos(shell)下执行使用。
[python]view plaincopy
- [智普教育 @ www.jeapedu.com]# sendEmail --help
- sendEmail-1.56 by Brandon Zehm <caspian@dotconf.net>
- Synopsis: sendEmail -f ADDRESS [options]
- Required:
- -f ADDRESS from (sender) email address
- * At least one recipient required via -t, -cc, or -bcc
- * Message body required via -m, STDIN, or -o message-file=FILE
- Common:
- -t ADDRESS [ADDR ...] to email address(es)
- -u SUBJECT message subject
- -m MESSAGE message body
-s SERVER[:PORT] smtp mail>
- Optional:
- -a FILE [FILE ...] file attachment(s)
- -cc ADDRESS [ADDR ...] cc email address(es)
- -bcc ADDRESS [ADDR ...] bcc email address(es)
- -xu USERNAME username for SMTP authentication
- -xp PASSWORD password for SMTP authentication
- Paranormal:
- -b BINDADDR[:PORT] local host bind address
- -l LOGFILE log to the specified file
- -v verbosity, use multiple times for greater effect
- -q be quiet (i.e. no STDOUT output)
- -o NAME=VALUE advanced options, for details try: --help misc
- -o message-content-type=<auto|text|html>
- -o message-file=FILE -o message-format=raw
- -o message-header=HEADER -o message-
- -o reply-to=ADDRESS -o timeout=SECONDS
- -o username=USERNAME -o password=PASSWORD
- -o tls=<auto|yes|no> -o fqdn=FQDN
- Help:
- --help the helpful overview you're reading now
--help addressing explain addressing and>
--help message explain message body input and>
- --help networking explain -s, -b, etc
- --help output explain logging and other output options
- --help misc explain -o options, TLS, SMTP auth, and more
测试用例
我(sender@163.com)要给他/她(receiver@sina.com)发电子邮件,邮件的主题是"subjectTitle",邮件的内容是说句“hello”,带了附件attach.txt文件,我邮箱sender@163.com的密码是“123456”,则使用sendEmail的命令如下:
[python]view plaincopy
- sendEmail -f sender@163.com -t receiver@sina.com -s smtp.163.com -xu sender@163.com -xp 123456 -u subjectTitle -m hello -a attach.txt
注:本示例在windows平台下测试,需手动使用dos即运行->cmd->cd c:/sendEmail目录(假设下载文件解压到本目录)
-f 后指定在邮箱里显示谁发的邮件 -t 后指定发给谁
-s 指定发送smtp服务器,本例用163的smtp服务器
-xu 后需指定smtp服务器上的授权帐号(sender@163.com),
实际上就是用参数xu后边的邮箱来真正发送邮件
-xp 后则是smtp服务器上的授权帐号(sender@163.com)所对应的密码,
smtp服务器要检查合法性
-u 邮件主题
-m 邮件正文内容
-a 邮件携带附件(attach.txt)
各位网友在自我测试时,需对应替换。比如想用“se@163.com(密码abcdef)”发邮件给"re@sina.com",邮件主题“hello”,邮件内容"world",携带附件"b.txt",我来替换一下如下:
[python]view plaincopy
- sendEmail -f se@163.com -t re@sina.com -s smtp.163 -xu se@163.com -xp abcdef -u hello -m world -a b.txt
4 编写发送邮件程序
写个Python程序来用用吧:发几百封邮件给他/她/Ta.程序名sm.py,请保存在sendEmail.exe同一目录下。
[python]view plaincopy
- import os
- from = "sender@163.com"
- to = "reveiver@sina.com"
- subject = "say hello"
- msg = "I like you"
- attachfile = "a.txt"
- c = 0
- while c < 498:
- os.system("sendEmail.exe -f "+from+" -t "+to+" -xu "+from+" -xp 123456 -u "+subject+" -s smtp.163.com -a "+attachfile+" -m "+msg)
- c = c + 1
据说163邮件一天最多发500封信,之后。。。呵呵,何时解封时间不确定,我看可以多申请几个163邮箱。 在sendEmail目录下执行python sm.py即可发499封邮件给他/她/Ta.
5. 怎样使发送邮件内容为Html的呢?
首先在sm.py文件所在目录下创建一个html文件,例如a.html,代码如下:
[html]view plaincopy
- <html>
- <body>
- <B>Python培训专家</B><br>
- <ahref= "http://www.jeapedu.com"><fontcolor = 'blue'size = '7'><u>智普教育 www.jeapedu.com</u></font></a>
- </body>
- </html>
接着,需要在sendEmail命令行里增加几个可以发送html文本作为邮件正文内容的参数选项。
[python]view plaincopy
- -o message-content-type=html
- -o message-charset=CHARSET
- -o message-header=HEADER
- -o message-file=afile
-o message-content-type = html
告诉邮件服务器发送的是html格式邮件内容
-o message-charset = CHARSET
这里不能用utf-8否则邮件内容显示乱码
-o message-file=某文件
是用来指定携带的那个html网页文件作为邮件正文, 这样邮件正文里就可以有超级链接了。
最后运行测试。
测试代码如下:
[python]view plaincopy
- # coding:utf-8
- # Created on 2013.8.28
- # Copyright @ 智普教育
- # www.jeapedu.com
- # Author 智普教育博客
- import os
- f = "jeapedu009@163.com"
- t="jeapedu@sina.cn"
- file = "a.html"
- subject = "say hello"
- os.system("sendEmail.exe -f "+f+" -t "+t+" -xu "+f+" -xp Yourpassword -u "+subject+" -s smtp.163.com -o message-content-type=html -o message-header=HEADER -o message-charset=CHARSET -a README.txt -o message-file="+file)
- print"ok"
邮箱收到邮件正文是html格式的邮件,如下所示。
|
|
|