As mailx is not part of the Cygwin distribution, you don't have that many choices if you want to send an email from a shell script. In this regard, Jeremy Reed has kindly provided a nice substitute script that can help us out:
http://cygwin.com/ml/cygwin/2005-02/msg00635.html
If you have Cygwin installed, you'll need to do the following things:
1) install ssmtp
2) configure ssmtp with ssmtp-config
3) install Jeremy's mailx shell programs
There are a couple of gotchas with step 2 above.
1) make sure you have the directory /etc/ssmtp created
- for some reason, the ssmtp-config program doesn't create it
2) make sure you define a fully qualified hostname
- if not, you'll get the following error
$ /usr/bin/mailx -s "test" cacasododom@gmail.com < test.txt
3) make sure that you have a symbolic link created for /usr/sbin/sendmail that links to /usr/sbin/ssmtp and that /usr/sbin is in your PATH. Otherwise, you'll get this error:
$ mailx.sh -s "test" joe.user@yahoo.com < test.txt
That's it.
I preferred to use Jeremy's program over nail, because it gives me the same arguments as mailx did.
Thanks Jeremy!
TAG
Showing posts with label smtp. Show all posts
Showing posts with label smtp. Show all posts
Thursday, February 28, 2008
Monday, October 22, 2007
command line to send test email via SMTP
Because I always forget this, here is the command line syntax for sending a test email through an SMTP mail server. Commands to enter at a prompt are in RED.
telnet mail.whateverdomain.com 25
Connected to whateverdomain.com.
Escape character is '^]'.
220-whateverdomain.com Smail-3.2.0.101 (#2 1998-Jul-16) ready at Mon, 27 Nov 2000 13: 34:55 -0600 (EST)
HELO yourmachine.yourdomain.com
250 yourdomain.com Hello yourmachine.yourdomain.com (yourdomain.com from address 64.214.123.23).
MAIL FROM:foo@yourdomain.com
250 foo@yourdomain.com ... Sender Okay
RCPT TO:joe_user@yahoo.com
250 'joe_user@yahoo.com' Recipient Okay.
DATA
354 Enter mail, end with "." on a line by itself
From: Meredith Foo
To: Joe
CC: foo@yourdomain.com
BCC: bar@yourdomain.com
Subject: Test Message
This is only a test.
.
250 Mail accepted
QUIT
221 whateverdomain.com closing connection
Don't forget that if your telnet session is hanging, the key combination of CTRL-] will exit you to the command prompt of telnet (Windows) or the shell prompt (Unix). If you're in Windows, simply type "quit" at the telnet command prompt in order to exit.
Expanding upon this simple test email, I've written some instructions on how to automate emails via shell script that some of you might find useful:
/2007/08/attaching-binary-file-to-command-line.html
cheers,
sodo
telnet mail.whateverdomain.com 25
Connected to whateverdomain.com.
Escape character is '^]'.
220-whateverdomain.com Smail-3.2.0.101 (#2 1998-Jul-16) ready at Mon, 27 Nov 2000 13: 34:55 -0600 (EST)
HELO yourmachine.yourdomain.com
250 yourdomain.com Hello yourmachine.yourdomain.com (yourdomain.com from address 64.214.123.23).
MAIL FROM:foo@yourdomain.com
250 foo@yourdomain.com ... Sender Okay
RCPT TO:joe_user@yahoo.com
250 'joe_user@yahoo.com' Recipient Okay.
DATA
354 Enter mail, end with "." on a line by itself
From: Meredith Foo
To: Joe
CC: foo@yourdomain.com
BCC: bar@yourdomain.com
Subject: Test Message
This is only a test.
.
250 Mail accepted
QUIT
221 whateverdomain.com closing connection
Don't forget that if your telnet session is hanging, the key combination of CTRL-] will exit you to the command prompt of telnet (Windows) or the shell prompt (Unix). If you're in Windows, simply type "quit" at the telnet command prompt in order to exit.
Expanding upon this simple test email, I've written some instructions on how to automate emails via shell script that some of you might find useful:
/2007/08/attaching-binary-file-to-command-line.html
cheers,
sodo
Labels:
command line,
key combinations,
smtp,
telnet
Subscribe to:
Posts (Atom)
Feel free to drop me a line or ask me a question.
