1 (edited by atesin 2016-09-16 19:49:13)

Topic: [Howto] Sending mail using Gmail SMTP

i needed this so i searched and now i want to share with you, is very easy, you can accomodate this basic example to your needs... maybe would be good if include this settings in luci in the future and use it for sending some events:

  • first enable your gmail account to use less secure applications (google >account settings >login&security >at bottom)

  • install 'ssmtp' throught luci or uci

  • edit /etc/ssmtp/ssmtp.conf

mailhub=smtp.gmail.com:587
hostname=your.domain
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthUser=your.account@gmail.com
AuthPass=your.password
  • you can create a mail.txt file (or use stdin or whatever)

From: "your alias" <your.account@gmail.com>
Subject: ssmtp test

your message
blah
  • now you can send your mail, and optionally add "-v" to view servers dialog

root@OpenWrt:/etc/ssmtp# cat mail.txt|ssmtp -v your.recipient@his.domain
[<-] 220 smtp.gmail.com ESMTP qweqweqweqwe.23 - gsmtp
[->] EHLO your.domain
[<-] 250 SMTPUTF8
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO your.domain
[<-] 250 SMTPUTF8
[->] AUTH LOGIN
[<-] 334 sdfsdFSDFsdfSDF
[->] fsdFSDFsdfDSFSDfSDFsdF
[<-] 334 asdASDasDASDS
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<your.account@gmail.com>
[<-] 250 2.1.0 OK qweqweqweqwe.23 - gsmtp
[->] RCPT TO:<your.recipient@his.domain>
[<-] 250 2.1.5 OK qweqweqweqwe.23 - gsmtp
[->] DATA
[<-] 354  Go ahead qweqweqweqwe.23 - gsmtp
[->] Received: by your.domain (sSMTP sendmail emulation); Fri, 16 Sep 2016 16:15:10 +0000
[->] Date: Fri, 16 Sep 2016 16:15:10 +0000
[->] From: "your alias" <your.account@gmail.com>
[->] Subject: ssmtp test
[->]
[->] your message
[->] blah
[->] .
[<-] 250 2.0.0 OK 1474042513 qweqweqweqwe.23 - gsmtp
[->] QUIT
[<-] 221 2.0.0 closing connection qweqweqweqwe.23 - gsmtp

Re: [Howto] Sending mail using Gmail SMTP

I tried sending email by telnet connection to MX record of gmail and at the end I got the message that my WAN IP is suspicious and gmail did not send the email.

3 (edited by atesin 2016-09-22 05:57:04)

Re: [Howto] Sending mail using Gmail SMTP

smtp servers have a lot of anti spam measures nowadays... dns checks, encryption, etc ... i think telnet support for gmail smtp server is unlikely

.. another trivial check is if the domain part of your mail address matches with sender's ip in dns .. if differs could means you are not the owner of the domain, your message could be considered as spam, discarded, and your ip or domain blocked worldwide

if this could be as easy everyone could send mails, rendering the whole email system useless due spam floods

if you have a gmail account or other with smtp support, try to use the describe method instead ..  i use for alerting on my servers connectivity loss smile

Re: [Howto] Sending mail using Gmail SMTP

Sending this way is fine, but now my trick is to get this working from PHP sendmail. hmm

Re: [Howto] Sending mail using Gmail SMTP

afaik ssmtp package which comes with centos includes a sendmail wrapper ...  if not you can write your own (i made it and added profiles and some extra security)

do some tests and check php documentation