Linux configuration -- ssmtp: Cannot open smtp.gmail.com:587
Solution 1
I encountered the same problem. The following steps worked for me:
- sudo vi /etc/ssmtp/ssmtp.conf Add the following:
TLS_CA_FILE=/etc/pki/tls/certs/ca-bundle.crt
[email protected]
mailhub=smtp.gmail.com:587
AuthUser=XXXX
AuthPass=XYXYX
UseSTARTTLS=Yes
UseTLS=Yes
hostname=AAAA
Replace: XXXX- username(mail) XYXYX- password(mail password) AAAA- hostname(get by running $hostname)
- sudo vi /etc/ssmtp/revaliases Add the following:
root:[email protected]:smtp.gmail.com:587
Replace : XXXX - username(mail)
-
Try running the mail now:
$mail -s "adasdas" [email protected]
CC: XYZLoremIpsum . 'ctrl+D'
It solved my problem. Hopefully for a system(Office) you need to configure correct proxy settings otherwise you will get an error:
cannot send message: Process exited with a non-zero status
Solution 2
try changing this option
Allowing less secure apps to access your account
https://support.google.com/accounts/answer/6010255?hl=en
Solution 3
This is perhaps because you're not setting the hostname
parameter of ssmtp.conf
. It should be a resolvable, fully-qualified domain name; yours is defaulting to the machine name of ctmtest
(as shown in the EHLO
command that you quote above).
The issue that user963 mentions in their answer may also be in action here, but in that case you'll get a different error message, something like ssmtp: Authorization failed (534 5.7.14 ...)
.
Solution 4
first to get your hostname type in terminal : hostname
copy it and past in hostname parameter in ssmtp.conf
Solution 5
This should be a comment on Haider Raza's answer, but I am short of 1 rep point to comment lol.
From https://superuser.com/questions/431539/special-characters-in-ssmtp-password
ssmtp has bugs parsing passwords containing '=', ':' or '#'. You can use the following workaround:
feed the password directly in the command line argument
ssmtp -ap "Hash#Password" ...
alternatively put the password in an environment variable.
ssmtp -ap $PASSWD ...
Hope it helped.
Related videos on Youtube
Chandramani
Updated on July 09, 2022Comments
-
Chandramani almost 2 years
Hi I have RHEL5 with ssmtp installed on it ssmtp-2.61-22.el5.i386.rpm
my /etc/ssmtp/ssmtp.conf updated as below :-
[email protected] AuthPass=mypassword FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES UseTLS=Yes RewriteDomain=gmail.com
also revaliases updated as below :
root:[email protected]:smtp.gmail.com:587
i have shutdown sendmail service
when i try to send email with ssmtp i get below error
[root@ctmtest ssmtp]# echo "test" | ssmtp -vvv [email protected] [<-] 220 smtp.gmail.com ESMTP v26sm42795996pfi.56 - gsmtp [->] EHLO ctmtest [<-] 250 SMTPUTF8 [->] STARTTLS [<-] 220 2.0.0 Ready to start TLS ssmtp: Cannot open smtp.gmail.com:587
i searched lots of tag with this error , but unable to fix this
my system is able to connect smtp.gmail.com on port 587
[root@ctmtest ssmtp]# telnet smtp.gmail.com 587 Trying 74.125.200.108... Connected to smtp.gmail.com (74.125.200.108). Escape character is '^]'. 220 smtp.gmail.com ESMTP o90sm11695907pfi.17 - gsmtp
is there anyone who have fixed this ? please suggest
-
Avi about 8 yearsDid you find a solution to this problem?
-
AlonMichaeli about 4 yearsThe answers below are correct, but I encountered this issue due to a network problem. The fix is documented here - stackoverflow.com/a/62062113/4196261
-
-
AstroFloyd almost 5 yearsThis solved my problem too; in particular, I had to add a
TLS_CA_FILE=/usr/share/ncat/ca-bundle.crt
line on my Arch Linux system after outgoing mail stopped working recently. -
Cameron Hudson over 4 yearsIs there a
mail
package on RHEL? There isn't one on CentOS. Not version 7, anyway. -
FreeSoftwareServers over 4 yearsIm so confused by your answer.... how does this relate to
ssmtp
at all -
jdavidbakr about 4 yearsThe
mail
package is installed withyum install mailx
-
jdavidbakr about 4 yearsRan into the same problem, except sending via SES at AWS. The
TLS_CA_FILE
line also solved it for me. -
AllisLove almost 3 yearsThanks for you time, thanks. God is here.
-
Griner about 2 yearsIn artix I had to use
TLS_CA_FILE=/usr/share/kf5/kssl/ca-bundle.crt