views:

1887

answers:

5

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.

+3  A: 
#!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.

Dan Lorenc
This will send an email *from* a Gmail account, to another Gmail or any other address...
David Zaslavsky
...and I guess the point of that comment would be, does the OP have a Gmail account available to send from? If not (or if he/she prefers not to use it), an SMTP or Sendmail API solution would be called for.
David Zaslavsky
The question didn't say where the email had to be sent from...
Dan Lorenc
Well, the OP's login name is unknown (google), which led me to believe he/she had a gmail account...
Dan Lorenc
Thanks David, the account is gmail- correct. This may be the ticket! I will try and let you know. Never used Perl, but I hear it is very robust and the programmers of Perl are very loyal!Thanks Again!
Antone
Sory I meant Python
Antone
Thank you Dan for the help, I will still get your ideas and certainly plan on looking into Perl or Python to replace the VBScript I have now for the module of the application.Thanks again!Antone
Antone
+4  A: 

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.

muteW
Thanks- if the Python code does not work out, but I think it will I will check this next.
Antone
Thank you muteW for the help, I will still get your ideas and certainly plan on looking into Perl or Python to replace the VBScript I have now for the module of the application.Thanks again!Antone
Antone
+4  A: 
Helen
i tried BLAT- did not work and sendmail and many others. Most seem to be using old code before - TLS. By the way I believe gmail does not work on 25 port. They use 465.
Antone
It would help if you expanded your question and told us which tools and/or code you tried and how exactly they "did not work" (what error messages you got etc), provide more information on your environment and so on. Maybe the problem is related to your environment/STMP server configuration and can be solded by adding additional settings to the code. But without knowing the details, it's hard to come up with anything else.
Helen
@Antone: Seems that Blat and Sendmail need an extra tool called *Stunnel* in order to work with Gmail (see the updated answer). I've also modified the VBScript example to use the Gmail SMTP server. Does it work for you now?
Helen
This is my third attempt to comment to you Helen. I seem unable to save my comments. Let's see if this works.
Antone
I am trying now your code. Seems I am able to save comments again. I logged off and back on earlier and that did not work either.Thank you for your help Helen!
Antone
Is this the complete code? It is not working for me. I will created a new email address in gmail and paste everthing to you. Incase I am not setting up parameters up correctly.Thanks!
Antone
c:\Python26\Lib\site-packages\libgmail>python setup.pyTraceback (most recent call last): File "setup.py", line 7, in <module> import libgmail File "C:\Users\Antone\Desktop\libgmail-0.1.11\libgmail.py", line 36, in <module> import mechanize as ClientCookieImportError: No module named mechanize
Antone
@Antone: Yes, it's the complete code. What do you mean by "not working"? Does a runtime error occurs? If so, what does the error say?
Helen
Helen, I try to past the code to you but i can not. So look below and you will see the email addres I created. If you could use this and test it for me that would be great!from: [email protected]: [email protected] password test1234
Antone
error is "send configuration is invalid" this is what i am using - i am sending and receving from the same gmail account for testing. I can not past all the code in because on limit of characters.I will post the code here as the link below. Give me 1 minute. Then you can comment on what is wrong. thanks!!! www.cardshock.com/helen.txt
Antone
the code is there now. i can also use another gmail address to send from if that is an issue.
Antone
@helen are you there?
Antone
@Antone: It works just fine for me (check the inbox). How do you actually launch the script? Does it work if you run the script's .VBS file itself (by double-clicking on it or using the `wscript filename.vbs` command)? Also, the error you posted above is Python's, how is it related to the present case?
Helen
goodie your back
Antone
i launch the script from the windows desktop by clicking the icon
Antone
yes the python was not suppose to go there - ignore that!
Antone
@helen - it does not work for me at all
Antone
@helen - the error states "sendusing configuration invalid"
Antone
@helen did you see the code i posted on the web?
Antone
@helen - ok so i see your email, did you send that with the code I posted on the web?
Antone
I am using the exact code I pasted on to the website I gave you and it is not working. I keep receiving the same error. My filename is x.vbs - i click it and then a messagebox comes up and says -"Error msg - line 20 char 1: Code: 80040220 source CDO.Message1
Antone
@helen - here is line 19 char 1 "oMsg.Send"
Antone
@helen - can you paste the exact code you used to make it work?Thanks!
Antone
yes - well very busy, i am doctor now not programmer anymore!
Antone
@helen - i deleted the email thanks for helping me!
Antone
A: 

In Linux (I'm not sure what environment you're on) you can use mail:

some_command| mail [email protected] [email protected] -s "subject"
Nathan Fellman
I am using Windows.
Antone
+2  A: 

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.

Alexandr Ciornii
Thanks, I will look at this one.
Antone
Well - seems everyone has a solution without trying it out. I was hoping Python would do the trick, but it needs mechanize module as well and I can not find it. I guess I will download Perl next and try your solution now.I am amazed at all the experience here and it has now been 6 hours trying to find a solution to a simple script that sends email from a batch file. Wow!Thanks!
Antone
The closes anyone came it seems was a 24 year old girl from Russia. She was very helpful, but I think I have error in my script then she disappeared. So here I go with Perl!
Antone
Thank you Alexandr for the help, I will still get your ideas and certainly plan on looking into Perl or Python to replace the VBScript I have now for the module of the application.Thanks again!Antone
Antone