Friday, November 26, 2010

Command Line Mailer

For a lot of situations, a command line emailer comes in really useful

In the past I have used Blat, which has suited my needs perfectly. However in recent times, I have had more and more issues with Exchange and firewalls, so decided to see if I could write one for my needs.
And so came about CPS.MiniMailer. Its not very sophisticated (yet) but it does allow me to send mails through our Exchange 2008 server, as well as Google Mail.
Heres a breakdown of the switches

CPS.MiniMailer.exe
-hDisplays list of switches
-srvSMTP server address or name
-pSMTP Port number
-tMail To (multiple addresses separated by commas
-fMail From
-subSubject (enclose sentence in double quotes)
-bBody (if HTML mail, can be html formatted string)
-duDomain user (Exchange) or user name (GMail etc)

-dppassword for -du
-html1 for HTML formatted mail, 0 for plain text
-aAttachments, surround paths with double quotes, multiple files separated by comma's
With the mailer comes a config file, CPS.MiniMailer.exe.config and all the above values (apart from attachments) can be preset there, really useful for Mail server and user name. However if you pass in a switch, this will override the config value with your switch one, really useful for subject, body etc.
To edit the config file, open it into notepad, and find the relevant setting (so for the From setting we would look for <setting="From" serializeAs="String"> )and then edit the the text between the <value> and </value> tags.

An example of a command line (or batch file) using GMail is
CPS.MiniMailer.exe -srv smtp.gmail.com -p 587 -f mylogin@gmail.com -t blogs@cadpro.co.nz -sub "Test Gmail Mail" -du mylogin@gmail.com -dp myPassword
And for exchange

CPS.MiniMailer.exe -srv myExhcnageSrv -p 25 -f myname@mycompany.com -t blogs@cadpro.co.nz -sub "Test ExchangeMail" -du myDomainName -dp myDomainPassword

You can download the mailer from CADPRO Systems MiniMailer Utility

Please post any questions or comments, and when changes are made we'll append to this blog

0 comments:

Post a Comment