Jump to content

INetsmtpmail GUI


Recommended Posts

Hi i use a _INetSmtpMail script i got of the forum, and i am trying to make a gui for it but i always get an error while sending.

I use this script and it works fine

#Include<file.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;##################################

; Include

;##################################

#Include<file.au3>

;##################################

; Variables

;##################################

$s_SmtpServer = InputBox("SMTP©", "Type your SMTP server f.eks smtp.online.no (Googel your isp smtp mail server)")

$s_FromName = InputBox("From Name©", "Type the name the mail shuld be from, not mail") ; name from who the email was sent

$s_FromAddress = InputBox("From Email©", "Type the email it shal be sent from") ; address from where the mail should come

$s_ToAddress = InputBox("To Address©", "Who to send email to") ; destination address of the email - REQUIRED

$s_Subject = InputBox("Subject©", "Subject of the mail") ; subject from the email - can be anything you want it to be

$as_Body = InputBox("Text©", "Text in the mail") ; the messagebody from the mail - can be left blank but then you get a blank mail

$s_AttachFiles = InputBox("Attach File©", "A file you want to send, leave blank if non") ; the file you want to attach- leave blank if not needed

$s_CcAddress = "" ; address for cc - leave blank if not needed

$s_BccAddress = "" ; address for bcc - leave blank if not needed

$s_Username = "" ; username for the account used from where the mail gets sent - REQUIRED

$s_Password = "" ; password for the account used from where the mail gets sent - REQUIRED

$IPPort = 25 ; port used for sending the mail

$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS

;~ $IPPort=465 ; GMAIL port used for sending the mail

;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################

; Script

;##################################

Global $oMyRet[2]

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)

If @error Then

MsgBox(0, "Error sending message©", "Error code:" & @error & " Description:" & $rc)

Else

MsgBox(0, "Sucsess!©", "Mail Sent")

EndIf

;

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_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($as_Body,"<") and StringInStr($as_Body,">") Then

$objEmail.HTMLBody = $as_Body

Else

$objEmail.Textbody = $as_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

;Authenticated SMTP

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

;Update settings

$objEmail.Configuration.Fields.Update

; Sent the Message

$objEmail.Send

if @error then

SetError(2)

return $oMyRet[1]

EndIf

EndFunc ;==>_INetSmtpMailCom

;

;

; Com Error Handler

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); something to check for when this function returns

Return

EndFunc ;==>MyErrFunc

And this is my gui and i get an error when sending

#include <GUIConstants.au3>

#include <INet.au3>

GUISetIcon ("Untitled-1.ico")

GUICreate("Fake SMTP Mailer")

GUISetState (@SW_SHOW)

$s_SmtpServer = GUICtrlCreateInput ("Smtp Server (smtp.myisp.com)", 10, 10, 300, 20)

$s_FromName = GUICtrlCreateInput ("From Name (John Smith)", 10, 35, 300, 20)

$s_FromAddress = GUICtrlCreateInput ("From Address (Johnsmith@email.com)", 10, 60, 300, 20)

$s_ToAddress = GUICtrlCreateInput ("To Address (address@email.com)", 10, 85, 300, 20)

$s_Subject = GUICtrlCreateInput ("Subject", 10, 110, 300, 20)

$as_Body = GUICtrlCreateInput ("Body/Text", 10, 135, 300, 200)

$Button_Send = GUICtrlCreateButton ("Send!", 315, 310, 80)

GUICtrlCreateProgress(10, 344, 385)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $Button_Send

_INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)

If @error Then

MsgBox(0, "Error sending message©", "Error code:" & @error)

Else

MsgBox(0, "Sucsess!©", "Mail Sent")

EndIf

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

I get a error code 3..
Link to comment
Share on other sites

Hi i use a _INetSmtpMail script i got of the forum, and i am trying to make a gui for it but i always get an error while sending.

I use this script and it works fine

And this is my gui and i get an error when sending

I get a error code 3..

Your have to read the inputs first :D

GUICtrlRead ($control)oÝ÷ Ù:òr§ëaÉb殶­sbôæWE6×GÖÂb33c·5õ6×G6W'fW"Âb33c·5ôg&öÔæÖRÂb33c·5ôg&öÔFG&W72Âb33c·5õFôFG&W72Âb33c·5õ7V&¦V7BÂb33c¶5ô&öG

Hope it helps :)

Link to comment
Share on other sites

  • 11 years later...

Sorry for opening this ancient thread, but I have an old AutoIT app that I'd like to tweak a bit that includes this function. It works fine, but I'd like to be able to set the REPLY-TO header in the outgoing message. I've looked at the MS cdo/configuration pages but although I see reference to "reply-to", I'm not savvy enough to figure out how to incorporate that into the _InetSmtpMailCom function.

EDIT: SOLVED! I dug deep into the CDO.message docs and somehow figured out the right syntax! Simplest mod is to just go into the function and after the line that says  $objEmail.To = $s_ToAddress

Insert this line:
        $objEmail.ReplyTo = "joe@somedomain.com"

You could get fancy and make it a parameter for the function if you plan to reuse it!

 

Edited by wysocki
Found answer by experimenting!
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...