20101212

使用 esmtp 实现用命令行 发送邮件

使用 esmtp 实现用命令行 发送邮件

1. 配置
注意:password

young@ubuntu:~$ cat esmtprc
# Config file for ESMTP sendmail
identity=gift.young@gmail.com
hostname=smtp.gmail.com:587
username="gift.young@gmail.com"
password="my password"
starttls=required

# The SMTP host and service (port)
#hostname=localdomain:25

# The user name
#username=

# The password
#password=

# Whether to use Starttls
#starttls=disabled

# The certificate passphrase
#certificate_passphrase=

# The Mail Delivery Agent
#mda=""
young@ubuntu:~$

2. 邮件正文
注意 "To:"和 邮件正文最后的两个回车.

young@ubuntu:~$ cat mailbody.txt
Subject: test
To: gift.young@gmail.com
hello, world!


3. 命令行
注意:后台执行

young@ubuntu:~$ esmtp -C ./esmtprc -v -X log < mailbody.txt &
[2] 4303
young@ubuntu:~$ Connected to MTA
StartTLS OK (128 bits)
young@ubuntu:~$ From gift.young@gmail.com: 250 OK y42sm7182444wfd.10
To gift.young.1@gmail.com: 250 OK y42sm7182444wfd.10
To gift.young@gmail.com: 250 OK y42sm7182444wfd.10
Message data: .
Message sent: 250 OK 1292153405 y42sm7182444wfd.10
Disconnected to MTA

[2]- Done esmtp -t gift.young.1@gmail.com -C
./esmtprc -v -X log < mailbody.txt
young@ubuntu:~$

4. 收到的邮件

Return-Path: <gift.young@gmail.com>
Received: from ubuntu ([124.235.241.225])
by mx.google.com with ESMTPS id b11sm7188528wff.9.2010.12.12.03.34.00
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Sun, 12 Dec 2010 03:34:02 -0800 (PST)
Message-ID: <4d04b32a.0bb38e0a.696d.5f19@mx.google.com>
Date: Sun, 12 Dec 2010 03:34:02 -0800 (PST)
From: gift.young@gmail.com
Subject: test
To: gift.young@gmail.com
hello, world!
Date: Sun, 12 Dec 2010 19:34:01 +0800
From: gift.young@gmail.com
Message-Id: <1292153641.270233.4347@ubuntu>

No comments: