Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TIP: Gmail and sSMTP
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
ellotheth
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 123

PostPosted: Wed Dec 14, 2005 5:25 am    Post subject: TIP: Gmail and sSMTP Reply with quote

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:
    mailhub=smtp.gmail.com:587

  • It's just STARTTLS. Not STARTTLS and SSL, nor STARTTLS and TLS. Just STARTTLS:
    Code:
    UseSTARTTLS=YES

  • Login info can be put on the command line; I prefer to stuff it in here:
    Code:
    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:
    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
Back to top
View user's profile Send private message
Sheepdogj15
Guru
Guru


Joined: 07 Jan 2005
Posts: 430
Location: Backyard

PostPosted: Fri Dec 16, 2005 5:20 am    Post subject: Re: TIP: Gmail and sSMTP Reply with quote

ellotheth wrote:
Code:
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
Back to top
View user's profile Send private message
ellotheth
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 123

PostPosted: Fri Dec 16, 2005 12:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Fri Dec 16, 2005 3:46 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ellotheth
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 123

PostPosted: Fri Dec 16, 2005 4:01 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jimonade
Tux's lil' helper
Tux's lil' helper


Joined: 21 Apr 2004
Posts: 92
Location: USA, West Lafayette, IN

PostPosted: Wed Jan 25, 2006 3:57 am    Post subject: Reply with quote

i've tried various combos including the above as well as from (https://forums.gentoo.org/viewtopic-p-3011748.html) and i get the following or nothing...
Code:
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?
Back to top
View user's profile Send private message
ellotheth
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 123

PostPosted: Wed Jan 25, 2006 2:08 pm    Post subject: Reply with quote

jimonade wrote:
Code:
send-mail: Cannot open gmail.smtp.com:587

Should be smtp.gmail.com, I believe. Here's my ssmtp.conf:
Code:
root=myroot@mymail.com

mailhub=smtp.gmail.com:587

rewriteDomain=

FromLineOverride=YES

UseSTARTTLS=YES
AuthUser=myemail@gmail.com
AuthPass=foobar

_________________
monjoy
Back to top
View user's profile Send private message
jimonade
Tux's lil' helper
Tux's lil' helper


Joined: 21 Apr 2004
Posts: 92
Location: USA, West Lafayette, IN

PostPosted: Wed Jan 25, 2006 9:54 pm    Post subject: Reply with quote

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:
root=jimonade@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=jimonade@gmail.com
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=jimonade
AuthPass=samplepasswd


revaliases
Code:
root:jimonade@gmail.com:smtp.gmail.com:587
jim:jimonade@gmail.com:smtp.gmail.com:587


thank you ellotheth and thank you google.
Back to top
View user's profile Send private message
Ravak
n00b
n00b


Joined: 03 Feb 2006
Posts: 54
Location: GB/PL

PostPosted: Fri Feb 03, 2006 4:53 pm    Post subject: Reply with quote

By default:
Code:
-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:
-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.
Back to top
View user's profile Send private message
jimonade
Tux's lil' helper
Tux's lil' helper


Joined: 21 Apr 2004
Posts: 92
Location: USA, West Lafayette, IN

PostPosted: Fri Feb 03, 2006 5:03 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
troworld
Tux's lil' helper
Tux's lil' helper


Joined: 20 Dec 2003
Posts: 95
Location: ON, CA

PostPosted: Sun Mar 12, 2006 5:48 pm    Post subject: Reply with quote

I'm getting:

Code:
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:
[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 mailwrapper md5sum ssl"
Back to top
View user's profile Send private message
destr0yr
Tux's lil' helper
Tux's lil' helper


Joined: 29 Nov 2003
Posts: 80
Location: Kelowna, BC.

PostPosted: Sat Apr 15, 2006 3:24 am    Post subject: Reply with quote

troworld wrote:


I have mailx and "emerge -av ssmtp" says:
Code:
[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 mailwrapper md5sum ssl"

This works for me:
Code:
[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...
Back to top
View user's profile Send private message
HotBBQ
Apprentice
Apprentice


Joined: 03 Mar 2004
Posts: 275
Location: West Melbourne, FL

PostPosted: Mon Apr 17, 2006 5:35 pm    Post subject: Reply with quote

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

Code:
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:
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
Back to top
View user's profile Send private message
Elorian
n00b
n00b


Joined: 26 Mar 2004
Posts: 31
Location: Canada

PostPosted: Tue Apr 18, 2006 7:39 pm    Post subject: Reply with quote

Excellent HOWTO. Worked perfectly the first time through. :D
Back to top
View user's profile Send private message
destr0yr
Tux's lil' helper
Tux's lil' helper


Joined: 29 Nov 2003
Posts: 80
Location: Kelowna, BC.

PostPosted: Tue Apr 18, 2006 8:49 pm    Post subject: Reply with quote

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:
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>
Back to top
View user's profile Send private message
gasparov
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2006
Posts: 105

PostPosted: Wed Jul 26, 2006 4:31 pm    Post subject: Reply with quote

Hi,
I can't make it work
When I try to sendmail I can't write any body/or subject
Code:
 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:
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
Back to top
View user's profile Send private message
smdeep
n00b
n00b


Joined: 14 Feb 2005
Posts: 6

PostPosted: Sat Aug 05, 2006 6:45 pm    Post subject: Reply with quote

Hi
Excellent howto. Just got it working!

Thanks!
Sudeep
Back to top
View user's profile Send private message
mikegpitt
Advocate
Advocate


Joined: 22 May 2004
Posts: 3224

PostPosted: Sun Aug 13, 2006 8:36 pm    Post subject: Reply with quote

Great tip... FYI this also works on gmail for domains.
Back to top
View user's profile Send private message
nosatalian
Tux's lil' helper
Tux's lil' helper


Joined: 09 Apr 2004
Posts: 98

PostPosted: Sun Sep 17, 2006 10:42 pm    Post subject: desperation Reply with quote

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.
Back to top
View user's profile Send private message
Cagnulein
l33t
l33t


Joined: 18 Sep 2003
Posts: 861
Location: Modena, Italy

PostPosted: Wed Sep 20, 2006 11:14 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Reistlin
n00b
n00b


Joined: 06 Sep 2005
Posts: 3

PostPosted: Sat Sep 30, 2006 11:24 pm    Post subject: Re: desperation Reply with quote

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 :(
Back to top
View user's profile Send private message
Thesee
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jun 2004
Posts: 138
Location: Belgium

PostPosted: Tue Oct 10, 2006 11:05 am    Post subject: Reply with quote

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:
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.
Back to top
View user's profile Send private message
krisse
Guru
Guru


Joined: 15 Mar 2005
Posts: 325
Location: Sweden

PostPosted: Thu Mar 01, 2007 5:23 pm    Post subject: Reply with quote

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.)
Back to top
View user's profile Send private message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Tue Mar 20, 2007 10:49 am    Post subject: Re: desperation Reply with quote

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.
Back to top
View user's profile Send private message
nosatalian
Tux's lil' helper
Tux's lil' helper


Joined: 09 Apr 2004
Posts: 98

PostPosted: Fri Mar 23, 2007 7:53 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum