Sign in to follow this  
Followers 0
Jex

Mail Sender

35 posts in this topic

#1 ·  Posted (edited)

I'm added gui for Jos's Smtp UDF

Posted Image

#Include <File.au3>
#include <GUIConstants.au3>
#include <String.au3>
Global $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl, $oMyRet[2], $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$Width = 322
$Height = 382
$Form = GUICreate("Mail Sender", $Width, $Height, -1, -1, BitOR($WS_POPUP, $WS_BORDER))
$Close = GUICtrlCreateLabel("X", $Width - 15, 0, 11, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Other = GUICtrlCreateLabel("+", $Width - 30, 0, 11, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Formtitle = GUICtrlCreateLabel(" Mail Sender", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Formtitlebackground = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22)
GUICtrlSetBkColor(-1, 0x000000)
$Edit1 = GUICtrlCreateEdit("", 8, 76, 305, 265)
$Input1 = GUICtrlCreateInput("", 56, 28, 257, 21)
$Input2 = GUICtrlCreateInput("", 56, 52, 257, 21)
$Label1 = GUICtrlCreateLabel("To :", 8, 30, 23, 17)
$Label2 = GUICtrlCreateLabel("Subject :", 8, 54, 46, 17)
$Button1 = GUICtrlCreateButton("Send", 8, 348, 150, 25, 0)
$Button2 = GUICtrlCreateButton("Settings", 167, 348, 147, 25, 0)

$Width2 = 263
$Height2 = 217
$Form2 = GUICreate("Settings", $Width2, $Height2, -1, -1, BitOR($WS_POPUP, $WS_BORDER))
$Close2 = GUICtrlCreateLabel("X", $Width2 - 15, 0, 11, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Formtitle2 = GUICtrlCreateLabel(" Settings", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Formtitlebackground2 = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22)
GUICtrlSetBkColor(-1, 0x000000)
$Label12 = GUICtrlCreateLabel("Smtp Server :", 16, 32, 68, 17)
$Label22 = GUICtrlCreateLabel("From name :", 16, 128, 62, 17)
$Label32 = GUICtrlCreateLabel("From address :", 16, 152, 73, 17)
$Label42 = GUICtrlCreateLabel("Username :", 16, 80, 58, 17)
$Label52 = GUICtrlCreateLabel("Password :", 16, 104, 56, 17)
$Label62 = GUICtrlCreateLabel("Port :", 16, 56, 29, 17)
$Label72 = GUICtrlCreateLabel("SSL :", 120, 56, 30, 17)
$Input12 = GUICtrlCreateInput("", 96, 32, 121, 21)
$Input22 = GUICtrlCreateInput("", 56, 56, 49, 21)
$Input32 = GUICtrlCreateInput("", 96, 80, 121, 21)
$Input42 = GUICtrlCreateInput("", 96, 104, 121, 21, $ES_PASSWORD)
$Input52 = GUICtrlCreateInput("", 96, 128, 121, 21)
$Input62 = GUICtrlCreateInput("", 96, 152, 121, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Enable / Disable", 152, 56, 97, 17)
$Button12 = GUICtrlCreateButton("Apply Settings", 16, 184, 83, 25, 0)
$Button22 = GUICtrlCreateButton("Apply and Save Settings", 112, 184, 131, 25, 0)

$Width3 = 283
$Height3 = 115
$Form3 = GUICreate("Options", $Width3, $Height3, -1, -1, BitOR($WS_POPUP, $WS_BORDER))
$Close3 = GUICtrlCreateLabel("X", $Width3 - 15, 0, 11, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Formtitle3 = GUICtrlCreateLabel(" Options", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Formtitlebackground3 = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22)
GUICtrlSetBkColor(-1, 0x000000)
$Label13 = GUICtrlCreateLabel("Cc :", 16, 34, 23, 17)
$Label23 = GUICtrlCreateLabel("Bcc", 16, 59, 23, 17)
$Label33 = GUICtrlCreateLabel("Attach :", 16, 82, 41, 17)
$Input13 = GUICtrlCreateInput("", 64, 32, 201, 21)
$Input23 = GUICtrlCreateInput("", 64, 56, 201, 21)
$Input33 = GUICtrlCreateInput("", 64, 80, 121, 21)
$Button13 = GUICtrlCreateButton("Browse", 192, 80, 75, 25, 0)

GUISetState(@SW_SHOW, $Form)
Load()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Close
            Save()
            Exit
        Case $Button1
            GUICtrlSetState($Button1, $GUI_DISABLE)
            GUICtrlSetData($Button1, "Loading...")
            $s_ToAddress = GUICtrlRead($Input1)
            $s_Subject = GUICtrlRead($Input2)
            $s_Body = GUICtrlRead($Edit1)
            $s_CcAddress = GUICtrlRead($Input13)
            $s_BccAddress = GUICtrlRead($Input23)
            $s_AttachFiles = GUICtrlRead($Input33)
            $Send = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
            If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & "  Rc:" & $Send)
            GUICtrlSetData($Button1, "Send")
            GUICtrlSetState($Button1, $GUI_ENABLE)
        Case $Button2
            GUISetState(@SW_SHOW, $Form2)
        Case $Other
            GUISetState(@SW_SHOW, $Form3)
        Case $Close2
            GUISetState(@SW_HIDE, $Form2)
        Case $Button12
            Apply()
        Case $Button22
            Save()
        Case $Button13
            $File = FileOpenDialog('Please choose file', '', 'All files (*.*)', 1)
            GUICtrlSetData($Input33, $File)
        Case $Close3
            GUISetState(@SW_HIDE, $Form3)
    EndSwitch
WEnd

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($s_Body, "<") And StringInStr($s_Body, ">") Then
        $objEmail.HTMLBody = $s_Body
    Else
        $objEmail.Textbody = $s_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                $i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    $objEmail.Configuration.Fields.Update
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
EndFunc   ;==>_INetSmtpMailCom

Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1)
    Return
EndFunc   ;==>MyErrFunc

Func Apply()
    $s_SmtpServer = GUICtrlRead($Input12)
    $s_FromName = GUICtrlRead($Input52)
    $s_FromAddress = GUICtrlRead($Input62)
    $s_Username = GUICtrlRead($Input32)
    $s_Password = GUICtrlRead($Input42)
    $IPPort = GUICtrlRead($Input22)
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        $ssl = "1"
    Else
        $ssl = "0"
    EndIf
EndFunc   ;==>Apply

Func Save()
    Apply()
    $Save = _StringEncrypt(1, $s_SmtpServer & "†" & $s_FromName & "†" & $s_FromAddress & "†" & $s_Username & "†" & $s_Password & "†" & $IPPort & "†" & $ssl, "Secret")
    If FileExists("Settings.txt") Then FileDelete("Settings.txt")
    FileWrite("Settings.txt", $Save)
EndFunc   ;==>Save

Func Load()
    If FileExists("Settings.txt") Then
        $Load = FileRead("Settings.txt")
        $Decrypt = _StringEncrypt(0, $Load, "Secret")
        $Settings = StringSplit($Decrypt, "†", 1)
        GUICtrlSetData($Input12, $Settings[1])
        GUICtrlSetData($Input52, $Settings[2])
        GUICtrlSetData($Input62, $Settings[3])
        GUICtrlSetData($Input32, $Settings[4])
        GUICtrlSetData($Input42, $Settings[5])
        GUICtrlSetData($Input22, $Settings[6])
        If $Settings[7] = "1"  Then
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
        Else
            GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
        EndIf
        Apply()
    EndIf
EndFunc   ;==>Load
Edited by Jex

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

Not Bad Jex.... :P

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Good work! :P


Console Browse: Navigate on the WEB in a textual consoleMultiPing!: Show computer on the lan and/or show the local/remote task, ALL animated!KillaWin: Event executingCryptPage: Crypt your webpage and show only with key

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hotmail, you cant use as it doesn't allow Pop3. I'm sure of it.

It needs SMTP or Secure SMTP to send its messages. POP is to retrieve your mail. :P Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Looks Good

Share this post


Link to post
Share on other sites

very simple :P

tnx


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

how come i can't copy the code???

try to upload the script!!

Share this post


Link to post
Share on other sites

Very nice!

Can you add the option for the user to enter contact information?

Also can it send me the pc information that it is coming from?

host, ip, mac, user, along with the comments?

Share this post


Link to post
Share on other sites

Can be used as a portable email sender :) good job

thx a lot!!

Share this post


Link to post
Share on other sites

Really, and I mean Really nice work!

Share this post


Link to post
Share on other sites

Really, and I mean Really nice work!

Hope you don't mind Jex, but I plan to use the way you've developed your GUI's in this project, into one of mine... :) bit different though. Gonna add some other things, but I'll post what I can get done with the GUI anway. ;)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Nice work....but i have a question...how can i send mail in HTML format? :)

Edited by Synapse

Share this post


Link to post
Share on other sites

Just so great! I am going to need this!

It could be implemented into a program as a bug "tracker" so that the bugs automaticly are stored in a file and then sent throught this!

Thanks for posting it!!

Share this post


Link to post
Share on other sites

How can I send mail from @yahoo.com? Is it possible? How? I really need such a program, but I haven`t managed to send anything yet.

Share this post


Link to post
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
Sign in to follow this  
Followers 0