OpenWrt Forum Archive

Topic: [Howto] Sending mail using Gmail SMTP

The content of this topic has been archived on 1 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

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
  • you can create a mail.txt file (or use stdin or whatever)

From: "your alias" <>
Subject: ssmtp test

your message
  • 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 ESMTP qweqweqweqwe.23 - gsmtp
[->] EHLO your.domain
[<-] 250 SMTPUTF8
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO your.domain
[<-] 250 SMTPUTF8
[<-] 334 sdfsdFSDFsdfSDF
[->] fsdFSDFsdfDSFSDfSDFsdF
[<-] 334 asdASDasDASDS
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<>
[<-] 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" <>
[->] 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

(Last edited by atesin on 16 Sep 2016, 21:49)

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.

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

(Last edited by atesin on 22 Sep 2016, 07:57)

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

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

The discussion might have continued from here.