使用mail,mailx,sendmail,curl发送邮件

【mail】
echo hello | mail -s ‘hello’ roben@test.com

【mailx】
echo “this is content” | mailx -s “this is title” roben@test.com

【sendmail】
{
echo “From: roben@test.com”
echo “To: roben@test.com”
echo “Subject: This is subject”
echo “This is body”
} | /usr/sbin/sendmail -t

 
【curl】
curl -V 查看版本;要支持SMTP(或者POP3)协议,curl的版本必须高于7.20(含)

发送邮件的命令如下:
需要认证:
curl -v -s –url “smtp://192.168.170.130:25″ –mail-from “roben@test.com” –mail-rcpt “roben@test.com” –upload-file mail.txt –user “roben:xxxxxx”

不需要认证:
curl -v -s –url “smtp://192.168.170.130:25″ –mail-from “roben@test.com” –mail-rcpt “roben@test.com” –upload-file mail.txt

mail.txt 内容如下,注意要有空行
cat mail.txt
From:roben@test.com
To:roben@test.com
Subject: this is subject

this is body
参数说明:
-v 回显调试信息
–url :smtp地址
–mail-from:发件人邮箱
–mail-rcpt:收件人邮箱
–upload-file:信件内容,包含发件人、收件人、标题、内容
–user:账号密码,中间用冒号分隔
[root@localhost Roben]# curl -v -s –url “smtp://192.168.170.130:25″ –mail-from “roben@test.com” –mail-rcpt “roben@test.com” –upload-file mail.txt
* About to connect() to 192.168.170.130 port 25 (#0)
* Trying 192.168.170.130…
* Connected to 192.168.170.130 (192.168.170.130) port 25 (#0)
< 220 test ESMTP Postfix
> EHLO mail.txt
< 250-test
< 250-PIPELINING
< 250-SIZE 10240000
< 250-VRFY
< 250-ETRN
< 250-AUTH LOGIN PLAIN
< 250-ENHANCEDSTATUSCODES
< 250-8BITMIME
< 250 DSN
> MAIL FROM:<roben@test.com> SIZE=102
< 250 2.1.0 Ok
> RCPT TO:<roben@test.com>
< 250 2.1.5 Ok
> DATA
< 354 End data with <CR><LF>.<CR><LF>
} [data not shown]
* We are completely uploaded and fine
< 250 2.0.0 Ok: queued as EAF6284038
* Connection #0 to host 192.168.170.130 left intact
[root@localhost Roben]#

使用mail,mailx,sendmail,curl发送邮件》有1个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>