[SOLVED] getting ssmtp to work with gmail + openmailbox.org

Kernels & Hardware, configuring network, installing services

[SOLVED] getting ssmtp to work with gmail + openmailbox.org

Postby debiman » 2016-06-06 06:26

edit:
original title of this thread was: ssmtp - Cannot open smtp.gmail.com:587
it is solved for both gmail and openmailbox now, please see below.
_________________________________________________________________


I have a debian stable home server running.
apache & the website & cherrymusic are working just fine, but i cannot send any mail.

i need this for the contact page of my website, so that php can send mail, and the common solution seems to be to use sendmail, which seems to default to ssmtp on debian (at least the wiki tells me so).

I have been at this literally for months, on and off.
i also have a notion why it is not working: it was working previously, but then i've been messing around with dovecot and exim4, then purged the packages again but don't remember anymore all the files i changed.
also, while i was trying to set up ssl for my server, i made alterations to /etc/hosts and i don't remember anymore what the default should be.
yep, blame me for not making backup copies.

the current situation is such that i get the error message from the title when trying to send mail with /usr/sbin/ssmtp, both as root and as a normal user, both with firewall disabled or enabled.
this is an improvement, previously ssmtp would just hang for minutes, giving some timeout error in the end.

my current /etc/ssmtp/ssmtp.conf:
Code: Select all
root=someone@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthUser=someone@gmail.com
AuthPass=verysecret
AuthMethod=LOGIN
# this last line added after reading serverfault.com/a/560805
TLS_CA_Dir=/etc/ssl/certs

i also tried with port 465, not sure why, some askubuntu answer recommended that.

i tried telnet like here, and get the same response, it connects.

my normal user is in the mail group.

i also moved /etc/hosts* (host.conf hostname hosts hosts.allow hosts.deny) to a backup folder, and rebooted the system. surprisingly, it did not re-create /etc/hosts, but everything seems to be working fine (except ssmtp of course).

thanks for reading.
ANY help greatly appreciated.
i am at the end of my tether.

========================
other things i tried previously (as far as i remember):
- set up ssmtp exactly as outlined here (obviously, this didn't work. it does seem old & outdated)
Last edited by debiman on 2016-06-08 05:07, edited 5 times in total.
User avatar
debiman
 
Posts: 2900
Joined: 2013-03-12 07:18

Re: ssmtp - Cannot open smtp.gmail.com:587

Postby pylkko » 2016-06-06 08:55

Have you activated 'allow less secure apps' from your gmail profile? Becauae I seem to recall that otherwise google will not allow many applications to access rhw account for security reasons. I have used ssmtp with gmail on Debian succwsfully, so that in itself should not be a problem
User avatar
pylkko
 
Posts: 1335
Joined: 2014-11-06 19:02

Re: ssmtp - Cannot open smtp.gmail.com:587

Postby debiman » 2016-06-07 04:27

pylkko wrote:activated 'allow less secure apps' from your gmail profile?

yes, it is activated.

there's been some development; i discovered that ssmtp has a verbose switch.
i also discovered that i'm using it wrong; now i'm testing with a properly formatted mail.txt.

here's what i get:
Code: Select all
/usr/sbin/ssmtp -vt < mail.txt
[<-] 220 smtp.gmail.com ESMTP z6sm1855964lbf.45 - gsmtp
[->] EHLO
[<-] 501 5.5.4  https://support.google.com/mail/?p=helo z6sm1855964lbf.45 - gsmtp
ssmtp: Cannot open smtp.gmail.com:587

now, changing my /etc/ssmtp/ssmtp.conf:
Code: Select all
root=someone@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=nn.nn.nn.nn (my IP)
hostname=nn.nn.nn.nn
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthUser=someone@gmail.com
AuthPass=verysecret
AuthMethod=LOGIN

(added my IP address as rewritedomain and hostname)

now the mail is being delivered!

however, i would like to use openmailbox.org instead of gmail, and there it doesn't work, but i'm getting a different error:
Code: Select all
ssmtp: Cannot open mailhub:25
(both with firewall disabled and enabled)

strangely, because i have provided what i believe to be the right mailhub:
Code: Select all
mailhub=smtp.openmailbox.org:465
Last edited by debiman on 2016-06-08 05:08, edited 1 time in total.
User avatar
debiman
 
Posts: 2900
Joined: 2013-03-12 07:18

Re: ssmtp Cannot open smtp.gmail.com:587 Cannot open mailhub

Postby debiman » 2016-06-07 05:44

it is solved for openmailbox, too.

i have no clue how this happened, but to openmailbox i could only write as root.
to be able to send mail as a normal user, i had to fix permissions on /etc/ssmtp/ssmtp.conf etc. as outlined here (also for /etc/ssmtp/revaliases, see below).

but that only enabled me to send mail with the same "From" address as is my openmailbox account.
this is a specialty of openmailbox, i guess.
to make it work with my website's email form, i additionally had to:
  • set up both rewriting in /etc/ssmtp/ssmtp.conf and /etc/ssmtp/revaliases both for root and normal user:
    Code: Select all
    # /etc/ssmtp/ssmtp.conf:
    root=someone@openmailbox.org
    normaluser=someone@openmailbox.org
    # /etc/ssmtp/revaliases:
    root:someone@openmailbox.org:smtp.openmailbox.org:465
    username:someone@openmailbox.org:smtp.openmailbox.org:465
  • disallow users to set their own from address in /etc/ssmtp/ssmtp.conf:
    Code: Select all
    FromLineOverride=NO

i hope this helps someone.
i changed the title of the thread to describe the solution.
Last edited by debiman on 2016-06-08 05:06, edited 1 time in total.
User avatar
debiman
 
Posts: 2900
Joined: 2013-03-12 07:18

Re: [SOLVED] getting ssmtp to work with gmail + openmailbox.

Postby pylkko » 2016-06-07 06:30

Ok. Interesting I would have assumed that openmailbox just does not allow FromLineOverride=Yes at all.

By the way, one of the comments in your linked thread says:

ssmtp does NOT verify the SSL/TLS certificate of the remote server on the current debian, ubuntu and redhat releases and also does NOT verify the hostname of the certificate. This is a major issue, as this effectively renders the encryption useless and your password is being transmitted alike to being plaintext and anyone can sniff it. ssmtp has had no active development since atleast 2009. So, if you care about the security of the email account you use for your servers outgoing emails, do NOT use ssmtp, but postfix (or something else) instead: unix.stackexchange.com/a/118101/72087



I had an application for personal use (not a server that other people than me use) that included automatic mailing via gmail with ssmtp and I then switched to using a Python module "yagmail". (https://github.com/kootenpv/yagmail)
User avatar
pylkko
 
Posts: 1335
Joined: 2014-11-06 19:02


Return to System configuration

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable