I need a tiny Windows script to send a 1 line email to Gmail accounts. I have tried many utilities that claim to do this such as BLAT, but none work. The script will be executed inside a batch file if certain conditions are met. Script can be in Perl, Python, VBScript, Java, it does not matter as long as it executes from a batch file. Please only answer if you have tried your solution by sending an email to a Gmail account from either a Gmail, Hotmail or Yahoo email account. The account I am using by default is Gmail, so I am sending from a Gmail account to a Gmail account.
views:
1887answers:
5#!c:/Python/python.exe -u
import libgmail
ga = libgmail.GmailAccount("[email protected]", "password")
ga.login()
msg=libgmail.GmailComposedMessage("[email protected]", "SubjectHere", "BodyHere")
ga.sendMessage(msg)
That should run on Windows using python. Make sure you change the shebang at the top to point to your python installation. Other than that, just enter your name and password, along with the email you want to send.
Have a look at this script on perlmonks which details IMAP access on a GMail account. The post covers everything you need to login into a GMail account through Perl.
Alternatively you could try the Mail::Webmail::Gmail module in CPAN. From the looks of it the module lets you skip most of the intricate details concerning connecting and authenticating with the mail server leaving you with something as simple as -
my $gmail = Mail::Webmail::Gmail->new( username => 'username', password => 'password', );
$gmail->send_message( to => '[email protected]', subject => 'Test Message', msgbody => 'This is a test.' );
There's also Email::Send::Gmail in case you need to 'only' send emails from a Gmail account.
In Linux (I'm not sure what environment you're on) you can use mail
:
some_command| mail [email protected] [email protected] -s "subject"
If you need just to send to GMail using some SMTP, use MIME::Lite Perl module in SMTP mode - I use it to send notifications to my GMail account.