Getting started
- Get an account from SMTP server, e.g. smtp.163.com.
- Install sendmail on Ubuntu 14.04.
Steps
1. Add the domain name(163.com) to /etc/hosts
127.0.0.1 localhost
127.0.1.1 myusername-Rev-1-0 163.com
2. Add authentication for SMTP server
mkdir /etc/mail/auth
Add the following line to client-info
AuthInfo:smtp.163.com "U:{somebody}@163.com" "I:{somebody}@163.com" "P:password"
Generate client-info.db by running
makemap hash auth/client-info < auth/client-info
Below is the files in /etc/mail/auth
/etc/mail/auth/
├── client-info
└── client-info.db
3. Modify /etc/mail/sendmail.mc
Add the following lines above the MAILER DEFINITIONdnl The following allows relaying if the user authenticates,
dnl and disallows plaintext authentication (PLAIN/LOGIN) on
dnl non-TLS links:
define(`confAUTH_OPTIONS', `A p y')dnl
MASQUERADE_AS(`163.com')dnl
MASQUERADE_DOMAIN(`163.com')dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl
define(`SMART_HOST',`smtp.163.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
4. Run
sendmailconfig
Test
Run mail or sendmail to send an Email.
mail -s "Some fancy title" -r {somebody}@163.com {guest}@aliyun.com <<< "This is the body of our email"
Or
sendmail -t -f{somebody} < /testMail.txt
where the contents of testMail.txt are
From: {somebody}@163.com
To: {guest}@aliyun.com
Subject: About the holiday
Mime-Version: 1.0
Content-Type: text/html
<body>
Hi,
This is the mail body.
</body>
</html>
May 19 17:22:32 myusername-Rev-1-0 sm-mta[3230]: u4J8h1lA000457: to=<{guest}@aliyun.com>, ctladdr=<{somebody}@163.com> (1001/1001), delay=00:39:31, xdelay=00:00:01, mailer=relay, pri=300436, relay=smtp.163.com. [220.181.12.17], dsn=2.0.0, stat=Sent (Mail OK queued as smtp13,EcCowACXTzbXhT1X6JpUCg--.64283S3 1463649752)
Reference
http://stackoverflow.com/questions/10359437/sendmail-how-to-configure-sendmail-on-ubuntuhttp://backreference.org/2013/05/22/send-email-with-attachments-from-script-or-command-line/