AutoHotkey Community

It is currently May 26th, 2012, 7:18 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: May 28th, 2009, 5:55 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Class: Email 0.5
Interface: EmailI 0.6

Description
An Email class (standard-library compatible) which implements my EmailI interface and provides email sending functionality through AHK in an object-oriented fashion.

Download
Email.zip

To use this, or any, class in AHK, you need the Class library. You can get the Class library here: Class.zip. Simply extract all files to one of the two AHK library directories (usually My Documents\AutoHotKey\lib)

Example Usage
Code:
#Include Email.ahk
#Include EmailI.ahk

; Set some message-related variables
SmtpServer = your.smtpserver.com
SmtpPort = 25
SmtpUsername = yourusername
SmtpPassword = yourpassword
from = You <you@yourdomain.com>
to = Someone Else <someone@somedomain.com>
subject = Test message
Body := "This is the body...`n`nIt is where your message goes.`n`n--`nAnd your signature"
html := false
priority = 3
attachment =  ; Put a file path here

; Create the message and set your options
Msg := Email_new(from, to, subject, body)
Email_setPriority(Msg, priority)
Email_smtpServer(Msg, SmtpServer, SmtpPort, SmtpUsername, SmtpPassword)
Email_setSendHTML(Msg, html)
if attachment
   Email_attach(Msg, attachment)

; Send the message
Email_send(Msg)


Instructions
1. Either place Email.ahk and EmailI.ahk in one of your AHK lib directories, or #include them in your script directly
2. Place blat.dll in a 'bin' subdir of your script (you can also use almost any other mailer--see below)
3. See Email_test.ahk for a basic usage example.
4. See Email.ahk to see what other functions are available
5. Wait for more documentation if you're not into experimenting :)

Explanation
I needed some email functionality for a script I am writing for work, and I wanted to keep it OOP, and not tied to any single email utility, since I have no way of knowing what we may want to use in the future.

So I wrote a neat little library to interface with Blat.dll (or Blat.exe, or any sendmail-like app) to send mail notifications via SMTP if my script fails.

In OOP terms, I wrote an Email interface (EmailI) that defines an Email object. I also implemented that interface in the Email class, which enables you to use almost any sendmail-like mailer (exe or dll) by configuring the constants.

What does this mean? If you're a user, you can utilize the Email class to send mail from your scripts. If you're into OOP for AHK, you can implement the EmailI Interface yourself and create your own email class!

Through the Email_constant() function, you can define many custom variables and parameter names in order to use almost any mailer needed, and place it wherever you want.

To demonstrate how easy it is through the most simple case possible, I've also included Blat.exe alongside Blat.dll. You can go ahead and delete it if you'd like. Or, if you prefer an Exe, try adding this toward the top of the above example:

Code:
Email_constant("mailerFile", "Blat.exe")
Email_constant("mailerIsExe", true)


And there you have it, the exact same email should be sent the exact same way, via Exe instead of Dll. By changing some dictionary values within the mailerOpts constant, you can change the parameter names of individual options corresponding to what's offered by most popular mailers. As long as you use Blat (included), you don't need to mess with that, however.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Last edited by bmcclure on June 1st, 2009, 8:50 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Features Coming Soon
PostPosted: May 28th, 2009, 6:16 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Coming soon to the Email class:
-Custom headers
-Full logging support (via my Log class)
-An EmailQueue class supporting batch message creation/sending
-Your suggestions
-More!

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2009, 12:18 pm 
Offline

Joined: January 26th, 2009, 7:14 am
Posts: 32
not working dude..
error with..

return Vector_add(Attachments, String_new(file))


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2009, 8:48 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Sorry, I forgot to be clear about this:

To use this, or any, class in AHK, you need the Class library. You can get the Class library here: Class.zip. Simply extract all files to one of the two AHK library directories (usually My Documents\AutoHotKey\lib)

Email functionality has been tested (maybe not 100%, however), and is being used in several of my scripts which need to send out notifications.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: infogulch and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group