Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Send email through GMail using mailsend


  • Please log in to reply
25 replies to this topic
Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008
I didn't reinvent the wheel on this one, but I think it's a useful post.  There's not a lot in the way of simple and complete solutions for command line e-mail through Gmail on the AutoHotKey forum.  This is about as plug-and-play as it gets.  The function just checks for 'mailsend' - a 3rd party command line e-mail application.  If not, it downloads it from the source.  Then, in a single line, you can pass all of the parameters.
 
Thanks to Guest-10, for your contributions!

Example
sendMail("ToEmail@gmail.com","YourPW","FromEmail@gmail.com","This is the subject line.","This is the email body.  Return keys must happen inline.`n`nUse the new line for that.","C:\file.txt")

Function

sendMail(emailToAddress,emailPass,emailFromAddress,emailSubject,emailMessage, fileLocation)
	{
        mailsendlocation := A_MyDocuments
	IfNotExist, %mailsendlocation%\mailsend1.17b12.exe
		URLDownloadToFile, https://mailsend.googlecode.com/files/mailsend1.17b12.exe, %mailsendlocation%\mailsend1.17b12.exe
	Run, %mailsendlocation%\mailsend1.17b12.exe -to %emailToAddress% -from %emailFromAddress% -ssl -smtp smtp.gmail.com -port 465 -sub "%emailSubject%" -M "%emailMessage%" +cc +bc -q -auth-plain -user "%emailFromAddress%" -pass "%emailPass%" -attach "%fileLocation%",, Hide
	}

ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

I downloaded and ran mailsend1.17b12.exe, but the first command line is preset to: SMTP server address/IP: not the c:\> command line. how do you get to c:\> command line?



Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008

I downloaded and ran mailsend1.17b12.exe, but the first command line is preset to: SMTP server address/IP: not the c:\> command line. how do you get to c:\> command line?

You literally just need to copy the two blocks I put above, put them in a text file, change the credentials, label it .ahk and double click.  It's that easy.  It takes care of downloading the right version & setting the parameters.

 

or you can call the function (top block) as many times from/to as many names as you want, triggered by whatever hotkey combination.


ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks, it worked. how do i send the following attachment "inline" so the text shows in the "body" of the message:?

C:\...\MyTextAttachment.txt



Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008

thanks, it worked. how do i send the following attachment "inline" so the text shows in the "body" of the message:?

C:\...\MyTextAttachment.txt

Ahh, I hadn't prepared for that.  You can modify the run command in the function to meet your needs.  Documentation here: https://code.google.com/p/mailsend/

 

The code is below.  I've made 3 changes.  (1) where you call the function, I've added the last parameter's value; in this case C:\file.txt.  (2) Where the function is declared, I've added the last parameter's variable name.  (3) At the end of the run command, i've passed the -attach command for Sendmail & added the variable that is passed.

sendMail("ToEmail@gmail.com","YourPW","FromEmail@gmail.com","This is the subject line.","This is the email body.  Return keys must happen inline.`n`nUse the new line for that.","C:\file.txt")
Function

sendMail(emailToAddress,emailPass,emailFromAddress,emailSubject,emailMessage,fileLocation)
	{
	global
	IfNotExist, %A_MyDocuments%\mailsend1.17b12.exe
		{
		URLDownloadToFile, https://mailsend.googlecode.com/files/mailsend1.17b12.exe, %A_MyDocuments%\mailsend1.17b12.exe
		}
	Run, %A_MyDocuments%\mailsend1.17b12.exe -to %emailToAddress% -from %emailFromAddress% -ssl -smtp smtp.gmail.com -port 465 -sub "%emailSubject%" -M "%emailMessage%" +cc +bc -q -auth-plain -user "%emailFromAddress%" -pass "%emailPass%" -attach "%fileLocation%"
	WinWait, %A_MyDocuments%\mailsend1.17b12.exe
	IfWinExist, %A_MyDocuments%\mailsend1.17b12.exe
		{
		WinHide
		}
	}

ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

great, thanks, i'll test and if any issues report back!



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

yes, it works great! after some struggle, i figured how to send files inline:

 

...,"C:\file.txt,text,i"

 

or, in general:

 

"file,MIME type,i" for inline.

 

bonus from FAQ:

(

Can an attachment be part of the mail body?

Yes. mailsend supports attachments as inline with the option -attach "file,MIME type,i". Any decent mail reader (gmail does, ThunderBird does) will display the attachment as a body of the mail but it is up to the mail reader to do so. mailsend can not do anything about it.

Microsoft Outlook does not support inline content-disposition MIME header by design. Please look at the Microsoft Knowledge base article http://support.microsoft.com/kb/814111 for detail.

My observation about Outlook 2010 is, if the very first attachment is attached as inline, it shows up as embedded in the body. The rest of the attachments show up as regular attachments, no matter what kind of content-disposition is used. I have no idea what kind of logic they are using!

)



dwilbank
  • Members
  • 367 posts
  • Last active: Dec 05 2015 12:57 AM
  • Joined: 20 Feb 2009

answering my own question,

 

to have multiple recipients, turn the +cc into a -cc and put the second email after it



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

does this mean +cc is for a single email address. also, can multiple email addresses be put after -cc (not just 2)?



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

i am using BLAT. which is better overall? BLAT or MailSend?



gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
Nice job

Blat is nice as you can use a dll version with dllcall

Lookup CDO email, you can also send from ahk directly using COM

Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

the reason i am using non-COM email is because of issues i have with COM on Windows 7 as documented extensively here:

http://www.autohotke.../page-4?hl=mail



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Any chance a GUI will be developed for this great script?  That way you can write an email and send it straight from your desktop. :)



Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008

Any chance a GUI will be developed for this great script?  That way you can write an email and send it straight from your desktop.

GUIs are easy. Just download Scite4AutoHotkey, hit F1 to get the editor & you've got a GUI editor that looks a lot like Visual Basic.

 

TBH, I don't see the sense in writing my own, standalone e-mail client.  Outlook or Thunderbird do it better than I can.  I just wanted a command line mailer to e-mail me in the event that one of my scripts fails and needs to be recovered immediately. I figured a few of us had that need.  Everything else seems more complicated than it's worth.


ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

If i use your script does that mean any emails i send will be non-encrypted?