How to send Email through external SMTP server on Ubuntu 14.04

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 DEFINITION
dnl  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>


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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值