Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

TIP: Gmail and sSMTP

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
38 posts
  • 1
  • 2
  • Next
Author
Message
ellotheth
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Tue Aug 30, 2005 3:02 pm

TIP: Gmail and sSMTP

  • Quote

Post by ellotheth » Wed Dec 14, 2005 5:25 am

TIP: Gmail and sSMTP

I recently set up Mutt with several non-Gmail accounts. When my non-Gmail SMTP server became a shade unreliable, I decided to use my Gmail SMTP server instead. (That's right, my Gmail server with non-Gmail email addresses.) Thus began several hours worth of forum-combing, Google-combing, documentation-combing, code-combing, and solution-by-trial-and-error. After much toil, I emerged triumphant, and I thought I'd use my newfound knowledge to spare similar hapless souls.

Gmail miscellany
  • Read Gmail's POP3 instructions for "other" mail clients.
  • Gmail's default behavior is to overwrite any unrecognized header information with its own. So if you're composing an email as <thetove@jabberwocky.com> in Mutt/Thunderbird/what-have-you and you send it via your <slithy.tove@gmail.com> account, it will arrive as an email from <slithy.tove@gmail.com>, with the <thetove@jabberwocky.com> nowhere in sight. Hardly ideal. You need to add "Custom From Addresses" in your Gmail account settings to preserve header info from non-Gmail addresses. Go to the "Accounts" section of "Settings." Add every account with which you plan to use the Gmail SMTP server, and don't forget to specify the reply-to.
sSMTP

Here's the part that sent me spinning across the internet. Gmail and sSMTP don't play nice without a little coaxing, and clear documentation is sparse.
  • Basic configuration documention/information is located in the default /etc/ssmtp/ssmtp.conf, so read it. Really. This is just a tip, not a HowTo. Jeez. Also read the contents of /usr/share/doc/ssmtp*/.
  • sSMTP needs port 587. It won't work (or rather, it doesn't for me) with 465, even if Google says it should. Hence:

    Code: Select all

    mailhub=smtp.gmail.com:587
  • It's just STARTTLS. Not STARTTLS and SSL, nor STARTTLS and TLS. Just STARTTLS:

    Code: Select all

    UseSTARTTLS=YES
  • Login info can be put on the command line; I prefer to stuff it in here:

    Code: Select all

    AuthUser=slithy.tove@gmail.com
    AuthPass=twasbrillig
    Authentication method (AuthMethod) defaults to LOGIN, which is what we want.
  • sSMTP needs to be told to pay attention to header info, too:

    Code: Select all

    FromLineOverride=YES
Caveat: With the above settings, your header info will still contain some references to Gmail: in particular, Return-Path and Sender will point to your gmail address by default. It doesn't bother me, so I haven't researched whether that's configurable.

That's it, you're golden. Happy...uh, non-Gmail Gmailing.

If this tip has been useful to you, let me know, yo. If it's completely unintelligible and worthless, let me know that too. I haven't written documentation in a long time, and I may well be out of practice.
monjoy
Top
Sheepdogj15
Guru
Guru
User avatar
Posts: 430
Joined: Fri Jan 07, 2005 9:02 am
Location: Backyard
Contact:
Contact Sheepdogj15
Website

Re: TIP: Gmail and sSMTP

  • Quote

Post by Sheepdogj15 » Fri Dec 16, 2005 5:20 am

ellotheth wrote:

Code: Select all

AuthUser=slithy.tove@gmail.com
AuthPass=twasbrillig
i'm going to assume this isn't your real password. ;)

hmm, interesting. right now i'm looking for a way to set up my Gentoo router/firewall box to send me alerts should someone attempt to hack it. this will definitely help (if you haven't noticed despite the "Guru" in my postbit i'm a bit of a newb at heart... i didn't even know Linux can send mail to me until today :lol:)
Sheepdog
Why Risk It? | Samba Howto
Top
ellotheth
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Tue Aug 30, 2005 3:02 pm

  • Quote

Post by ellotheth » Fri Dec 16, 2005 12:56 pm

Sheepdogj15 wrote:i'm going to assume this isn't your real password. ;)
O botheration! No one was supposed to guess!
:D
Sheepdogj15 wrote:i didn't even know Linux can send mail to me until today
Don't worry, I'm in roughly the same boat. "What are all these weird dead.letters in $HOME? Cron is trying to email me?! Cool!"
monjoy
Top
oliver
Apprentice
Apprentice
User avatar
Posts: 170
Joined: Wed Jun 25, 2003 9:39 pm

  • Quote

Post by oliver » Fri Dec 16, 2005 3:46 pm

I think cron only does that if your scripts generate output - send all to /dev/null (or an appropriate log file) and they'll stop
Top
ellotheth
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Tue Aug 30, 2005 3:02 pm

  • Quote

Post by ellotheth » Fri Dec 16, 2005 4:01 pm

oliver wrote:I think cron only does that if your scripts generate output - send all to /dev/null (or an appropriate log file) and they'll stop
Thanks, I did find that. It was really confusing for a while, though.
monjoy
Top
jimonade
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 92
Joined: Wed Apr 21, 2004 11:18 pm
Location: USA, West Lafayette, IN
Contact:
Contact jimonade
Website

  • Quote

Post by jimonade » Wed Jan 25, 2006 3:57 am

i've tried various combos including the above as well as from (http://forums.gentoo.org/viewtopic-p-3011748.html) and i get the following or nothing...

Code: Select all

mail -s "testing ssmtp" jim@example.com

...

send-mail: Cannot open gmail.smtp.com:587
Can't send mail: sendmail process failed with error code 1
any suggestions? or, could someone post their working (gmail) ssmtp.conf?
Top
ellotheth
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Tue Aug 30, 2005 3:02 pm

  • Quote

Post by ellotheth » Wed Jan 25, 2006 2:08 pm

jimonade wrote:

Code: Select all

send-mail: Cannot open gmail.smtp.com:587
Should be smtp.gmail.com, I believe. Here's my ssmtp.conf:

Code: Select all

root=myroot@mymail.com

mailhub=smtp.gmail.com:587

rewriteDomain=

FromLineOverride=YES

UseSTARTTLS=YES
AuthUser=myemail@gmail.com
AuthPass=foobar
monjoy
Top
jimonade
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 92
Joined: Wed Apr 21, 2004 11:18 pm
Location: USA, West Lafayette, IN
Contact:
Contact jimonade
Website

  • Quote

Post by jimonade » Wed Jan 25, 2006 9:54 pm

thanks so much for the reply. ssmtp is now working.

i think my problem was the revaliases file-- i had gmail.smpt.com isntead of smtp.gmail.com.

the below ssmtp.conf works even if all revaliases are comment out. then again, its just me and root on this box.

ssmtp.conf

Code: Select all

root=jimonade@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=jimonade@gmail.com
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=jimonade
AuthPass=samplepasswd
revaliases

Code: Select all

root:jimonade@gmail.com:smtp.gmail.com:587
jim:jimonade@gmail.com:smtp.gmail.com:587
thank you ellotheth and thank you google.
Top
Ravak
n00b
n00b
Posts: 54
Joined: Fri Feb 03, 2006 3:53 pm
Location: GB/PL
Contact:
Contact Ravak
Website

  • Quote

Post by Ravak » Fri Feb 03, 2006 4:53 pm

By default:

Code: Select all

-rw-r--r-- 1 root root 1285 lut  3 16:08 ssmtp.conf
So if you have any additional users/accounts I'd be careful with it.

Now by:

Code: Select all

-rw-r----- 1 root root 1285 lut  3 16:08 ssmtp.conf
Only root and his group can view the config. Unfrotunatenly, also only root can send mail.

So my question is how to secure config file without restricting access to mail service. I'd like to make one or two accounts for family members yet I dont want them to know my passes.

Thanks.
Top
jimonade
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 92
Joined: Wed Apr 21, 2004 11:18 pm
Location: USA, West Lafayette, IN
Contact:
Contact jimonade
Website

  • Quote

Post by jimonade » Fri Feb 03, 2006 5:03 pm

have my ssmtp.conf at chmod 640, so im in the same boat... only root can send with ssmtp.

i only really wanted ssmtp setup so that i could have cron jobs email me stuff periodically so it suits my needs. but i can see how you'd want to enable this for users as well as root while not allowing users to see the plain text passwords.

if anyone knows how to save the ssmtp password in a chmod 640 file and reference it in ssmtp.conf allowing all system users to email with ssmtp, please share!

edit: chmod 640 so that root's group has read access
Top
troworld
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 95
Joined: Sat Dec 20, 2003 12:05 am
Location: ON, CA

  • Quote

Post by troworld » Sun Mar 12, 2006 5:48 pm

I'm getting:

Code: Select all

mail -v -s "testing ssmtp" myemail
asdlfjhasdfasd
fasdfasdf
Cc:
[<-] 220 mx.gmail.com ESMTP e11sm2652278qbc
[->] EHLO email@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO email@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
Can't send mail: sendmail process failed
I have mailx and "emerge -av ssmtp" says:

Code: Select all

[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 mailwrapper md5sum ssl"
Top
destr0yr
Tux's lil' helper
Tux's lil' helper
Posts: 80
Joined: Sat Nov 29, 2003 10:02 am
Location: Kelowna, BC.
Contact:
Contact destr0yr
Website

  • Quote

Post by destr0yr » Sat Apr 15, 2006 3:24 am

troworld wrote:
I have mailx and "emerge -av ssmtp" says:

Code: Select all

[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 mailwrapper md5sum ssl"
This works for me:

Code: Select all

[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 -mailwrapper -md5sum ssl"
Do you absolutely require mailwrapper and md5sum? Try it without for testing purposes...
Top
HotBBQ
Apprentice
Apprentice
User avatar
Posts: 275
Joined: Wed Mar 03, 2004 9:02 pm
Location: West Melbourne, FL
Contact:
Contact HotBBQ
Website

  • Quote

Post by HotBBQ » Mon Apr 17, 2006 5:35 pm

I having problems with secure connection. Here is the error I am receiving:

Code: Select all

adam@Beast ~ $ mail -v -s "ssmtp test" adbowers@gmail.com
Hope this works.
Cc:
[<-] 220 mx.gmail.com ESMTP i35sm736090wxd
[->] HELO Beast
[<-] 250 mx.gmail.com at your service
[->] MAIL FROM:<adbowers@gmail.com>
[<-] 530 5.7.0 Must issue a STARTTLS command first i35sm736090wxd
send-mail: 530 5.7.0 Must issue a STARTTLS command first i35sm736090wxd
Can't send mail: sendmail process failed with error code 1
My ssmtp.conf:

Code: Select all

root=adbowers@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=adbowers@gmail.com
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=adbowers
AuthPass=***
Edit
Removing md5sum and mailwrapper from my use flags and recompiling seems to have fixed the problem. I cannot, however, mail with a user other than root.
"If tyranny and oppression come to this land, it will be in the guise of fighting a foreign enemy." -- James Madison
Top
Elorian
n00b
n00b
User avatar
Posts: 31
Joined: Fri Mar 26, 2004 7:11 pm
Location: Canada

  • Quote

Post by Elorian » Tue Apr 18, 2006 7:39 pm

Excellent HOWTO. Worked perfectly the first time through. :D
Top
destr0yr
Tux's lil' helper
Tux's lil' helper
Posts: 80
Joined: Sat Nov 29, 2003 10:02 am
Location: Kelowna, BC.
Contact:
Contact destr0yr
Website

  • Quote

Post by destr0yr » Tue Apr 18, 2006 8:49 pm

HotBBQ wrote: Edit
Removing md5sum and mailwrapper from my use flags and recompiling seems to have fixed the problem. I cannot, however, mail with a user other than root.
What do you have in /etc/ssmtp/revaliases?

AFAIK, it should be:

Code: Select all

root:user@gmail.com:smtp.gmail.com:587
linuxuser1:user@gmail.com:smtp.gmail.com:587
linuxuser2:user@gmail.com:smtp.gmail.com:587
...
<shameless plug>http://www.destr0yr.com/article.php/Gmail_and_sSMTP</shameless plug>
Top
gasparov
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 105
Joined: Thu Apr 13, 2006 4:42 pm

  • Quote

Post by gasparov » Wed Jul 26, 2006 4:31 pm

Hi,
I can't make it work
When I try to sendmail I can't write any body/or subject

Code: Select all

 echo lol|mail -v my@gmail.com -s "lol"
[<-] 220 mx.gmail.com ESMTP q13sm1257758qbq
[->] EHLO my@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO my@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] AUTH LOGIN bHVjYS5nYXNwZXJpbmk=
[<-] 334 UGFzc3dvcmQ6
[->] aWNzLjEzNzY=
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<my@gmail.com>
[<-] 250 2.1.0 OK
[->] RCPT TO:<my@gmail.com>
[<-] 250 2.1.5 OK
[->] RCPT TO:<lol@my@gmail.com>
[<-] 250 2.1.5 OK
[->] DATA
[<-] 354 Go ahead
[->] Received: by my@gmail.com (sSMTP sendmail emulation); Wed, 26 Jul 2006 18:20:50 +0200
[->] From: "root" <my@gmail.com>
[->] Date: Wed, 26 Jul 2006 18:20:50 +0200
[->]
[->] .
[<-] 250 2.0.0 OK 1153930856 q13sm1257758qbq
[->] QUIT
[<-]
As you can see two messages are sent,one is sento to lol@my@gmail.com ,the -s (even tried -S and moving it's position) doesn't work.
So I get a delivery notification on my account,the weird thing is that i don't get any mail on my account
For example this command

Code: Select all

echo lol|mail -v my@gmail.com
[<-] 220 mx.gmail.com ESMTP e16sm3775825qbe
[->] EHLO my@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO my@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] AUTH LOGIN bHVjYS5nYXNwZXJpbmk=
[<-] 334 UGFzc3dvcmQ6
[->] aWNzLjEzNzY=
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<my@gmail.com>
[<-] 250 2.1.0 OK
[->] RCPT TO:<my@gmail.com>
[<-] 250 2.1.5 OK
[->] DATA
[<-] 354 Go ahead
[->] Received: by my@gmail.com (sSMTP sendmail emulation); Wed, 26 Jul 2006 18:27:22 +0200
[->] From: "root" <my@gmail.com>
[->] Date: Wed, 26 Jul 2006 18:27:22 +0200
[->]
[->] .
[<-] 250 2.0.0 OK 1153931248 e16sm3775825qbe
[->] QUIT
[<-]
Says all "ok" but no mail arrive on my@gmail.com,so sending stuff seems to work because if i put a wrong email address after the mail command i get a delivery notification in my account but nothing is really sent,at least nothing arrives
Top
smdeep
n00b
n00b
Posts: 6
Joined: Mon Feb 14, 2005 12:31 pm

  • Quote

Post by smdeep » Sat Aug 05, 2006 6:45 pm

Hi
Excellent howto. Just got it working!

Thanks!
Sudeep
Top
mikegpitt
Advocate
Advocate
User avatar
Posts: 3224
Joined: Sat May 22, 2004 6:49 pm

  • Quote

Post by mikegpitt » Sun Aug 13, 2006 8:36 pm

Great tip... FYI this also works on gmail for domains.
Top
nosatalian
Tux's lil' helper
Tux's lil' helper
Posts: 98
Joined: Fri Apr 09, 2004 12:37 pm

desperation

  • Quote

Post by nosatalian » Sun Sep 17, 2006 10:42 pm

I can't seem to get this to work. My config files are exactly as everyone elses, but with the most recent (~arch) and stable in portage, I get a segfault when trying to connect. With older ssmtp versions, I just get a failure "Must issue a STARTTLS command first" even though my config file is identical, and I've already specified UseSTARTTLS=YES .

I get this segfault with the newer versions in portage, after getting past this step, and I can verify that it occurs on two different machines- one amd64, and one i686. I've made sure on both that my CFLAGS are minimal.
Top
Cagnulein
l33t
l33t
User avatar
Posts: 861
Joined: Thu Sep 18, 2003 3:39 pm
Location: Modena, Italy

  • Quote

Post by Cagnulein » Wed Sep 20, 2006 11:14 am

Little offtopic:
is there a way to store all the sent mail on a folder readable by mutt? I have already an imap server on my pc that stores incoming mail, now i want to store sent too (using my ISP SMTP server (tin.it)) . I think ssmtp it was i looking for, at least for the first target..
Thanks
Top
Reistlin
n00b
n00b
Posts: 3
Joined: Tue Sep 06, 2005 2:25 pm

Re: desperation

  • Quote

Post by Reistlin » Sat Sep 30, 2006 11:24 pm

nosatalian wrote:I can't seem to get this to work. My config files are exactly as everyone elses, but with the most recent (~arch) and stable in portage, I get a segfault when trying to connect. With older ssmtp versions, I just get a failure "Must issue a STARTTLS command first" even though my config file is identical, and I've already specified UseSTARTTLS=YES .

I get this segfault with the newer versions in portage, after getting past this step, and I can verify that it occurs on two different machines- one amd64, and one i686. I've made sure on both that my CFLAGS are minimal.
The same problem for me. sSMTP segfaults while trying to establish secure connection. Hovewer I run the stable amd64 with very few ~amd64 packages. Core dump shows nothing about origin of the error :(
Top
Thesee
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 138
Joined: Wed Jun 02, 2004 5:05 pm
Location: Belgium

  • Quote

Post by Thesee » Tue Oct 10, 2006 11:05 am

Cagnulein: a way to store all "sent mails" sent from mutt to a directory readable by mutt could achieved by writing this in your .muttrc:

Code: Select all

set record=+~/mail/sent-mail
Great howto by the way! I had it working with postfix, then, for an unknown reason, it didn't work anymore, and then I discovered this, and *WHAM* it works again! :)
How does a UNIX expert have sex?
Unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep.
Top
krisse
Guru
Guru
Posts: 325
Joined: Tue Mar 15, 2005 12:38 pm
Location: Sweden

  • Quote

Post by krisse » Thu Mar 01, 2007 5:23 pm

Everything works well when mails are sent to a complete email address (name@domain), however when trying to send to a local user "name", the mails is sent to "namegmailuser@gmail.com". That is, local username "name" is just prefixed to my gmail address.

Yes, I have a entry in /etc/ssmtp/revaliases.

The mail is sent by cron. (Sure, I can set the mail address in crontab to something else. But that's not a fix, just a way around the problem.)
Top
lcidw
Tux's lil' helper
Tux's lil' helper
Posts: 77
Joined: Mon Oct 18, 2004 5:00 pm

Re: desperation

  • Quote

Post by lcidw » Tue Mar 20, 2007 10:49 am

Reistlin wrote:
nosatalian wrote:I can't seem to get this to work. My config files are exactly as everyone elses, but with the most recent (~arch) and stable in portage, I get a segfault when trying to connect. With older ssmtp versions, I just get a failure "Must issue a STARTTLS command first" even though my config file is identical, and I've already specified UseSTARTTLS=YES .

I get this segfault with the newer versions in portage, after getting past this step, and I can verify that it occurs on two different machines- one amd64, and one i686. I've made sure on both that my CFLAGS are minimal.
The same problem for me. sSMTP segfaults while trying to establish secure connection. Hovewer I run the stable amd64 with very few ~amd64 packages. Core dump shows nothing about origin of the error :(
Build ssmtp without md5sum and mailwrapper.. It's one of those, too lazy to check which one. Had the same segfaults and with only the ssl flag, it works like a baby in water.
Top
nosatalian
Tux's lil' helper
Tux's lil' helper
Posts: 98
Joined: Fri Apr 09, 2004 12:37 pm

  • Quote

Post by nosatalian » Fri Mar 23, 2007 7:53 am

Weeks later, this is still dreadfully broken. I've tried with every combination of use flags. I was using esmtp after I gave up on this, but that doesn't work any longer either- I get weird 0 (null) messages. I'm not sure how this is working for everyone else.
Top
Post Reply

38 posts
  • 1
  • 2
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy