How to send Email through external SMTP server on Ubuntu 14.04

来源:互联网 发布:淘宝预售发货时间 编辑:程序博客网 时间:2024/06/05 09:38

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       localhost127.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 DEFINITION
dnl  The following allows relaying if the user authenticates,dnl  and disallows plaintext authentication (PLAIN/LOGIN) ondnl  non-TLS links:define(`confAUTH_OPTIONS', `A p y')dnlMASQUERADE_AS(`163.com')dnlMASQUERADE_DOMAIN(`163.com')dnlFEATURE(`masquerade_entire_domain')dnlFEATURE(`masquerade_envelope')dnldefine(`SMART_HOST',`smtp.163.com')dnldefine(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnlFEATURE(`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.comTo: {guest}@aliyun.comSubject: About the holidayMime-Version: 1.0Content-Type: text/html<body>Hi,This is the mail body.</body></html>


Check the log from /var/log/mail.log 

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-ubuntu
http://backreference.org/2013/05/22/send-email-with-attachments-from-script-or-command-line/
0 0
原创粉丝点击