Jump to content

Send Mail


 Share

Recommended Posts

Hello Gurus,

I have an AutoIt script here to send email with GUI (from Victor) which is working fine. But I need to have an attachment with browsing functionality. Below is the code.

#NoTrayIcon
#AutoIt3Wrapper_icon=alert.ico

#include 
#include 
#include 
#include 

;~ Email Subject
Global $VAR_SUBJECTX = "Alert - Emergency"
;~ Email Body (default)
Global $VAR_BODYMAIL = "Attention all employees. An emergency has taken place that requires evacuation of the building," & @CRLF & @CRLF
$VAR_BODYMAIL &= "please proceed in an orderly fashion to the safest exit." & @CRLF & @CRLF & "Thank you"
;~ Email SMTP Mail Server
Global $VAR_SMTPMAIL = "mail1"

$begin=MsgBox(0x4, "Emergency", "Are you sure you want to proceed?")
if $begin = 7 then exit

FNC_GUIEMAIL()

Func FNC_GUIEMAIL()
Local $CHK_BODYMAIL, $CHK_FROMMAIL, $CHK_SENDMAIL
Local $GUI_BODYMAIL, $GUI_FROMMAIL, $GUI_SENDMAIL
Local $MSG_FROMNAME, $MSG_FROMMAIL, $MSG_RESPONSE

GUICreate($VAR_SUBJECTX, 600, 215)

;~ Begin "From:" Gui Information
GUICtrlCreateLabel('From:', 10, 12, 50, 20)
$GUI_FROMMAIL = GUICtrlCreateCombo('', 65, 10, 525, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData($GUI_FROMMAIL, 'Emergency|Emergency1|Emergency2', 'Emergency')
;~ End "From:" Gui Information

;~ Begin "To:" Gui Information
GUICtrlCreateLabel('To:', 10, 37, 50, 20)
$GUI_SENDMAIL = GUICtrlCreateCombo('', 65, 35, 525, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData($GUI_SENDMAIL, 'alert@domain.com|alert1@domain.com|alert2@domain.com', 'alert@domain.com')
;~ End "To:" Gui Information

;~ Begin "Body:" Gui Information
GUICtrlCreateLabel('Body', 10, 62, 50, 20)
$GUI_BODYMAIL = GUICtrlCreateEdit($VAR_BODYMAIL, 65, 62, 525, 100, $WS_VSCROLL)
;~ End "Body:" Gui Information

$GUI_CLOSEMSG = GUICtrlCreateButton('Cancel', 490, 167, 100, 40)
$GUI_EMAILMSG = GUICtrlCreateButton('Send', 390, 167, 100, 40)

GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_CLOSEMSG
Exit
Case $GUI_EMAILMSG
$CHK_FROMMAIL = GUICtrlRead($GUI_FROMMAIL)
Select
Case $CHK_FROMMAIL = 'Emergency'
$MSG_FROMNAME = 'Emergency'
$MSG_FROMMAIL = 'alert@domain.com'
Case $CHK_FROMMAIL = 'Emergency1'
$MSG_FROMNAME = 'Emergency1'
$MSG_FROMMAIL = 'alert1@domain.com'
Case $CHK_FROMMAIL = 'Emergency2'
$MSG_FROMNAME = 'Emergency2'
$MSG_FROMMAIL = 'alert2@domain.com'
Case Else
$MSG_FROMNAME = 'Emergency'
$MSG_FROMMAIL = 'alert@domain.com'
EndSelect
$MSG_SENDMAIL = GUICtrlRead($GUI_SENDMAIL)
$MSG_BODYMAIL = GUICtrlRead($GUI_BODYMAIL)
$Response = _INetSmtpMail ($VAR_SMTPMAIL, $MSG_FROMNAME, $MSG_FROMMAIL, $MSG_SENDMAIL, $VAR_SUBJECTX, $MSG_BODYMAIL, @ComputerName, -1)
Switch @error
Case 1
$MSG_RESPONSE = 'Error: Invalid Parameters'
Case 2
$MSG_RESPONSE = 'Error: Unable to start TCP'
Case 3
$MSG_RESPONSE = 'Error: Unable to resolve IP'
Case 4
$MSG_RESPONSE = 'Error: Unable to create socket'
Case Else
$MSG_RESPONSE = 'Error: Unknown'
EndSwitch
If $Response = 1 Then $MSG_RESPONSE = 'Success: Message sent successfully'
MsgBox(0,$VAR_SUBJECTX, $MSG_RESPONSE)
EndSwitch
WEnd
EndFunc

Any help will be appreciated. Thanks in advance.

Link to comment
Share on other sites

You should redirect

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

search the forum for

Smtp Mailer That Supports Html And Attachments.

or simply

go to

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

May I recommend a loud speaker for a life threatening emergency as opposed to an email for one? XD

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...