21

Hi I have RHEL5 with ssmtp installed on it ssmtp-2.61-22.el5.i386.rpm

my /etc/ssmtp/ssmtp.conf updated as below :-

AuthUser=mymail@gmail.com
AuthPass=mypassword
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
UseTLS=Yes
RewriteDomain=gmail.com

also revaliases updated as below :

root:mymail@gmail.com: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 mymail@gmail.com
[<-] 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

Chandramani
  • 343
  • 1
  • 2
  • 9
  • Did you find a solution to this problem? – Avi Jun 10 '16 at 02:29
  • The answers below are correct, but I encountered this issue due to a network problem. The fix is documented here - https://stackoverflow.com/a/62062113/4196261 – AlonMichaeli May 28 '20 at 14:12

9 Answers9

28

I encountered the same problem. The following steps worked for me:

  1. sudo vi /etc/ssmtp/ssmtp.conf Add the following:

TLS_CA_FILE=/etc/pki/tls/certs/ca-bundle.crt root=XXXX@gmail.com 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)

  1. sudo vi /etc/ssmtp/revaliases Add the following:

root:XXXX@gmail.com:smtp.gmail.com:587

Replace : XXXX - username(mail)

  1. Try running the mail now:

    $mail -s "adasdas" XXXX@gmail.com

    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

boardrider
  • 5,882
  • 7
  • 49
  • 86
Haider Raza
  • 455
  • 5
  • 8
  • 2
    This 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. – AstroFloyd Aug 07 '19 at 09:01
  • Is there a `mail` package on RHEL? There isn't one on CentOS. Not version 7, anyway. – Cameron Hudson Mar 09 '20 at 23:54
  • The `mail` package is installed with `yum install mailx` – jdavidbakr Apr 15 '20 at 19:44
  • Ran into the same problem, except sending via SES at AWS. The `TLS_CA_FILE` line also solved it for me. – jdavidbakr Apr 15 '20 at 19:45
  • Thanks for you time, thanks. God is here. – AllisLove Jul 29 '21 at 22:31
  • In artix I had to use `TLS_CA_FILE=/usr/share/kf5/kssl/ca-bundle.crt` – Griner Jun 13 '22 at 19:34
  • Also note, unexpected: you will get the "Cannot open " error if the TLS_CA_FILE does not exist or if you do not have read permission on this file. – b0tting Aug 24 '22 at 08:31
  • First remember that AuthPass is a Google App password, not your email password. Second, I fixed it myself I fixed it by changing my hostname to hostname=localhost instead of hostname:emailaddress@gmail.com – user1097111 Apr 20 '23 at 00:51
5

try changing this option

Allowing less secure apps to access your account

https://support.google.com/accounts/answer/6010255?hl=en

user963
  • 51
  • 1
4

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 ...).

Community
  • 1
  • 1
Sam Wilson
  • 4,402
  • 4
  • 29
  • 30
2

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.

Skyfish
  • 119
  • 2
  • 4
1

first to get your hostname type in terminal : hostname

copy it and past in hostname parameter in ssmtp.conf

0

On my Gentoo Linux system, the error ssmtp: Cannot open smtp.server.com:port was caused by an ownership/permissions issue: the file /etc/ssmtp/ssmtp.conf should belong to the group ssmtp, which it didn't (and any user allowed to access ssmtp should be a member of that group).

AstroFloyd
  • 405
  • 5
  • 14
0

I ws looking for a solution for cacti smtp mail sender. And found myself actually sending an email using the postfix service . I also used localhost in the postfix config. Thanks!

0

This is my config for outlook365.com that works on Centos 6.10 (Final) - replace all [square brackets] with your own settings:

/etc/ssmtp/ssmtp.conf

root=[admin_emailemail@domain.ext]
mailhub=smtp.office365.com:587
RewriteDomain=[domain.ext]
# to find out run hostname command in shell
Hostname=[hostname_or_domain]
AuthUser=[your_smtp_authentication_mailbox@domain.ext]
AuthPass=[your_password]
AuthMethod=LOGIN
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
# Use SSL/TLS certificate to authenticate against smtp host.
# When enabled it was failing to send emails
#UseTLSCert=YES
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

/etc/ssmtp/revaliases

root:[your_sender_or_authentication_mailbox@domain.ext]:smtp.office365.com:587
webcoder.co.uk
  • 341
  • 3
  • 5
-2

Mail functions are all highly broken, so are the numerous tutorials on the internet.

This is pretty bad, for something that MUST be EASY for BEGINNERS.

A little panels of unclear errors you will face:

mailx: unrecognized option '-d'
 
mailx: unrecognized option '-v'

s-nail: Setting up PseudoRandomNumberGenerator: *SSL RAND_*
s-nail: New-style URL used without *v15-compat* being set
/home/you/dead.letter 3/106
s-nail: ... message not sent
 
s-nail: Connecting to XX.XX.XX.XXX:465 ... connected.
s-nail: SMTP: Resource temporarily unavailable

s-nail: Obsoletion warning: Use of old-style credentials, which will vanish in v15!

s-nail: Obsoletion warning: please don't use *smtp*: assign a smtp:// URL to *mta*!
 
s-nail: Unexpected EOF on SMTP connection


No, there is no needs of any credentials to send a simple mail.

STEP 1: Install mail-utils

sudo apt install mailutils

STEP 2: Install mutt

sudo apt install mutt

STEP 3: Run the postfix setup

sudo dpkg-reconfigure postfix

Usage press TAB to select OK

enter image description here

Select "Internet site"

enter image description here

Enter your domain, or whatever

enter image description here

Leave all other settings as default. (Press RETURN till the end)

Mails will then be sent from this email: yourCurrentsession@whatever.com

STEP 4: Apply settings

service postfix reload

STEP 5: Send email

echo "Hello world"  | mutt -s "Message sent at $(date)" recipient@gmail.com -y

STEP 6: Optional. Change sender email and name. Create a .muttrc file in the home folder.

echo -e "set from =  \"aname@something.net\"\nset realname = \"Yay\"" > ~/.muttrc
NVRM
  • 11,480
  • 1
  • 88
  • 87