Reputation: 1365
I have a written a shell script wherein I want to send an email through it. I am executing this script on windows through cygwin. I have installed email package on my machine. However, I am having a hard time making it work. Please let me know what is the easiest way to send email through cygwin command prompt.
My ssmtp.conf file is :
mailhub=smtp.gmail.com:587
FromLineOverride=YES
rewriteDomain=gmail.com
[email protected]
UseTLS=YES
AuthUser=userid
AuthPass=password
and email.conf file has:
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = '25'
MY_NAME = 'ABC'
MY_EMAIL = 'emailaddress'
REPLY_TO = 'emailaddress'
USE_TLS = 'true'
ADDRESS_BOOK = '&/email.address.template'
SMTP_AUTH = 'LOGIN'
SMTP_AUTH_USER = 'userid'
SMTP_AUTH_PASS = 'password'
I am using below command to send email: echo "mail body"|email -s "subject" [email protected] However, I am getting following error: email: FATAL: Could not connect to server: smtp.gmail.com on port: 25: Operation not permitted
Please help.
Upvotes: 2
Views: 7929
Reputation: 1
I use the msmtp
package, with this configuration:
port 587
auth on
from [email protected]
host smtp.gmail.com
tls on
tls_certcheck off
user [email protected]
https://cygwin.com/cgi-bin2/package-grep.cgi?grep=msmtp&arch=x86_64
Upvotes: 1
Reputation: 1645
Install and configure the ssmtp
package.
Create /bin/mail
with these contents:
#!/bin/sh
#
# copyright 2016 Gene Pavlovsky [http://www.razorscript.com]
#
# mail: mail-like wrapper script for sendmail
SENDMAIL=/usr/sbin/ssmtp
usage()
{
{
echo "Usage: $(basename $0) [-s "subject"] [-f from-addr] [to-addr]..."
echo
echo "Sends mail."
echo
echo "Options:"
echo -e " -s\tsubject (quote subjects containing spaces)"
echo -e " -f\tfrom address"
} >&2
exit 2
}
while test $# -gt 0; do
case $1 in
-s)
shift
test $# -eq 0 && usage
subj=$1
;;
-f)
shift
test $# -eq 0 && usage
from=$1
;;
-*)
usage
;;
*)
rcpt+=( "$1" )
;;
esac
shift
test "$end_options" = yes && break
done
test ${#rcpt} -eq 0 && usage
{
test "$from" && echo From: $from
test "$subj" && echo Subject: $subj
echo
exec /bin/cat
} | "$SENDMAIL" "${rcpt[@]}"
Don't forget to chmod 755 /bin/mail
.
Upvotes: 1