Email 通过命令行和GMail发送邮件

Email 通过命令行和GMail发送邮件,email,command-line,Email,Command Line,我想为BASH脚本创建一个粗略的框架,如果一个程序以非零结果退出,它会从同一个帐户向我的GMail帐户发送一封电子邮件 test "script to execute" then //Send me a mail with the content of /worked.txt else //Send me a mail with the content of /failed.txt fi 我读过,是这样的 mail mymail@gmail.com < /worked.txt 邮件my

我想为BASH脚本创建一个粗略的框架,如果一个程序以非零结果退出,它会从同一个帐户向我的GMail帐户发送一封电子邮件

test "script to execute"
then
//Send me a mail with the content of /worked.txt
else
//Send me a mail with the content of /failed.txt
fi
我读过,是这样的

mail mymail@gmail.com < /worked.txt
邮件mymail@gmail.com
它什么也没做 没有电子邮件,没有错误,什么都没有

-v现在说:

> foobar@gmail.com... Connecting to [127.0.0.1] via relay... 220
> my-laptop.lan ESMTP Sendmail
> 8.14.3/8.14.3/Debian-9.1ubuntu1; Wed, 10 Nov 2010 18:34:49 +0100; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
> >>> EHLO my-laptop.lan 250-my-laptop.lan Hello localhost [127.0.0.1], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-EXPN
> 250-VERB 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-AUTH DIGEST-MD5
> CRAM-MD5 250-DELIVERBY 250 HELP
> >>> VERB 250 2.0.0 Verbose mode
> >>> MAIL From:<foobar@my-laptop.lan> SIZE=220 AUTH=foobar@my-laptop.lan 250 2.1.0 <foobar@my-laptop.lan>... Sender
> ok
> >>> RCPT To:<foobar@gmail.com>
> >>> DATA 250 2.1.5 <foobar@gmail.com>... Recipient ok 354 Enter mail, end with "." on a line by itself
> >>> . 050 <foobar@gmail.com>... Connecting to gmail-smtp-in.l.google.com. via esmtp... 050 220 mx.google.com ESMTP
> c6si1047453fat.137 050 >>> EHLO my-laptop.lan 050 250-mx.google.com at
> your service, [188.19.112.229] 050 250-SIZE 35651584 050 250-8BITMIME
> 050 250 ENHANCEDSTATUSCODES 050 >>> MAIL From:<foobar@my-laptop.lan>
> SIZE=481 050 250 2.1.0 OK c6si1047453fat.137 050 >>> RCPT
> To:<foobar@gmail.com> 050 250
> 2.1.5 OK c6si1047453fat.137 050 >>> DATA 050 354  Go ahead c6si1047453fat.137 050 >>> . 050 250
> 2.0.0 OK 1289410490 c6si1047453fat.137 050 <foobar@gmail.com>... Sent (OK 1289410490 c6si1047453fat.137) 250 2.0.0 oAAHYn4X005767 Message
> accepted for delivery foobar@gmail.com... Sent (oAAHYn4X005767 Message
> accepted for delivery) Closing connection to [127.0.0.1]
> >>> QUIT 221 2.0.0 my-laptop.lan closing connection
>foobar@gmail.com... 通过继电器连接到[127.0.0.1]。。。220
>my-laptop.lan ESMTP Sendmail
>8.14.3/8.14.3/Debian-9.1ubuntu1;2010年11月10日星期三18:34:49+0100;(无UCE/UBE)日志访问来自:localhost(确定)-localhost[127.0.0.1]
>>>>EHLO my-laptop.lan 250-my-laptop.lan你好localhost[127.0.0.1],很高兴认识您250-ENHANCEDSTATUSCODES 250-pipelling 250-EXPN
>250-VERB 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-AUTH DIGEST-MD5
>CRAM-MD5 250-DELIVERBY 250帮助
>>>>动词250 2.0.0详细模式
>>>>邮件发件人:大小=220身份验证=foobar@my-laptop.lan 250 2.1.0。。。发件人
>嗯
>>>>RCPT至:
>>>>数据250 2.1.5。。。收件人确定354输入邮件,在一行上以“.”结束
> >>> . 050 ... 正在连接到gmail-smtp-in.l.google.com。通过esmtp。。。050 220 mx.google.com ESMTP
>c6si1047453fat.137 050>>>EHLO my-laptop.lan 050 250-mx.google.com
>您的服务,[188.19.112.229]050 250-SIZE 35651584 050 250-8BITMIME
>050 250增强状态代码050>>>邮件发件人:
>尺寸=481 050 250 2.1.0正常c6si1047453fat.137 050>>RCPT
>收件人:050250
>2.1.5正常c6si1047453fat.137 050>>数据050 354继续c6si1047453fat.137 050>>。050 250
>2.0.0正常1289410490 c6si1047453fat.137 050。。。已发送(OK 1289410490 c6si1047453fat.137)250 2.0.0 oAAHYn4X005767消息
>接受交货foobar@gmail.com... 已发送(oAAHYn4X005767消息
>接受交付)关闭与[127.0.0.1]的连接
>>>>退出221 2.0.0 my-laptop.lan关闭连接

我同意亚历克斯的观点。这应该行得通。你检查过GMail帐户上的垃圾邮件文件夹了吗?也许它到达了,但被自动归类为垃圾邮件


-mark

这应该可以正常工作,请尝试添加-v选项以查看它的功能。不,我只得到以下信息:050 550-5.7.1[188.22.234.229]您用于发送邮件的IP未授权050 550-5.7.1直接向我们的服务器发送电子邮件。请改用050 550-5.7.1服务提供商的SMTP中继。更多信息,请访问050505.7.1 P2SI225084BKW.36