Jump to content

[Solved] Run _INetSmtpMailCom after button clicked.


Recommended Posts

Hi Experts out there,

I need help in running Jos Smtp mailer that I found here "http://www.autoitscript.com/forum/index.ph...860&hl=smtp". This smtp mailer runs perfectly and great scripting done by Jos (big help for me). However, I made a button "Attachment" in my GUI that after browsing for attached file, mail should sent with attachment. In this case, the script will not run after browsing file.

$Attachment = GUICtrlCreateButton("Attachment", 456, 125, 81, 25)
GUICtrlSetOnEvent(-1, "AttachmentClick")

Here the code:

Func AttachmentClick()
   Local Const $sMessage = "Browsing file for attachment."
    DirCreate("D:\template\" & @UserName & "\"
    $FilePath = "D:\template\" & @UserName & "\"

    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
    If @error Then
        MsgBox(8192, "", "No file(s) were selected.", $Form1)
        Exit
    Else
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
         MsgBox(0, "", "You chose the following file(s):" & @CRLF & $sFileOpenDialog, 5)
        FileCopy($sFileOpenDialog, $FilePath)
     EndIf
EndFunc

$SmtpServer = "my.domain.com"
$FromName = "Samantha.Ruth"
$FromAddress = "Address1.com"
$ToAddress = "Address2.com"
$Subject = "Test mail"
$Body = "Test mail. Thank you!"
$AttachFiles =  GUICtrlRead($FilePath) & "Test.zip"
$CcAddress = ""
$BccAddress = ""
$Importance = "High"
$Username = "Advance123"
$Password = "*********"
$IPPort = 25
$ssl = 0

   Global $oMyRet[2]
   Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
   $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
   If @error Then
      MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
   EndIf
   Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $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])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                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
    If Number($IPPort) = 0 then $IPPort = 25
    $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") = 0
        $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 ("<a href='http://schemas.microsoft.com/cdo/configuration/smtpusessl' class='bbc_url' title='External link' rel='nofollow external'>http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
   MsgBox(64, @UserName, "Attached sent.", 5)
   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)
   Return
EndFunc
; The UDF

Thank you in advance.

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

1 hour ago, KickStarter15 said:

Hi Experts out there,

I need help in running Jos Smtp mailer that I found here "http://www.autoitscript.com/forum/index.ph...860&hl=smtp". This smtp mailer runs perfectly and great scripting done by Jos (big help for me). However, I made a button "Attachment" in my GUI that after browsing for attached file, mail should sent with attachment. In this case, the script will not run after browsing file.

$Attachment = GUICtrlCreateButton("Attachment", 456, 125, 81, 25)
GUICtrlSetOnEvent(-1, "AttachmentClick")

Here the code:

Func AttachmentClick()
   Local Const $sMessage = "Browsing file for attachment."
    DirCreate("D:\template\" & @UserName & "\"
    $FilePath = "D:\template\" & @UserName & "\"

    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
    If @error Then
        MsgBox(8192, "", "No file(s) were selected.", $Form1)
        Exit
    Else
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
         MsgBox(0, "", "You chose the following file(s):" & @CRLF & $sFileOpenDialog, 5)
        FileCopy($sFileOpenDialog, $FilePath)
     EndIf
EndFunc

$SmtpServer = "my.domain.com"
$FromName = "Samantha.Ruth"
$FromAddress = "Address1.com"
$ToAddress = "Address2.com"
$Subject = "Test mail"
$Body = "Test mail. Thank you!"
$AttachFiles =  GUICtrlRead($FilePath) & "Test.zip"
$CcAddress = ""
$BccAddress = ""
$Importance = "High"
$Username = "Advance123"
$Password = "*********"
$IPPort = 25
$ssl = 0

   Global $oMyRet[2]
   Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
   $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
   If @error Then
      MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
   EndIf
   Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $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])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                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
    If Number($IPPort) = 0 then $IPPort = 25
    $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") = 0
        $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 ("<a href='http://schemas.microsoft.com/cdo/configuration/smtpusessl' class='bbc_url' title='External link' rel='nofollow external'>http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
   MsgBox(64, @UserName, "Attached sent.", 5)
   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)
   Return
EndFunc
; The UDF

Thank you in advance.

Hello sir.  Sorry to hear about the issues you are experiencing.  I also know of the SMTP mailer script you are referring to, but I couldn't get it to work the way I needed to either.  I would like to propose an alternative.  Cmail is a command line utility which allows you to send email with attachments in exactly the way you descried.  I actually just finished writing a script that utilizes this utility and you will almost definitely be more successful in what you are attempting utilizing it.  Let me know if you have any questions if you are interested.

Link to comment
Share on other sites

Hi MattHiggs,

Thanks for the response. But I figured it out using call() function in help and it works perfectly as expected. ^_^

Here's the code:

$Attachment = GUICtrlCreateButton("Attachment", 10, 10, 10, 10)
GUICtrlSetOnEvent(-1, "AttachmentClick")

Func AttachmentClick()
   Local Const $sMessage = "Browsing file for attachment."
    DirCreate("D:\template\" & @UserName & "\"
    $FilePath = "D:\template\" & @UserName & "\"
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
    If @error Then
        MsgBox(8192, "", "No file(s) were selected.", $Form1)
        Exit
    Else
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
         MsgBox(0, "", "You chose the following file(s):" & @CRLF & $sFileOpenDialog, 5)
        FileCopy($sFileOpenDialog, $FilePath)
     EndIf
        $SmtpServer = "my.domain.com"
        $FromName = "Samantha.Ruth"
        $FromAddress = "Address1.com"
        $ToAddress = "Address2.com"
        $Subject = "Test mail"
        $Body = "Test mail. Thank you!"
        $AttachFiles =  $FilePath & "Test.zip"
        $CcAddress = ""
        $BccAddress = ""
        $Importance = "High"
        $Username = "Advance123"
        $Password = "********"
        $IPPort = 25
        $ssl = 0

   Global $oMyRet[2]
   Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
   $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
   If @error Then
      MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
   EndIf
   Call("_INetSmtpMailCom")
EndFunc

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $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])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                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
    If Number($IPPort) = 0 then $IPPort = 25
    $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") = 0
        $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 ("<a href='http://schemas.microsoft.com/cdo/configuration/smtpusessl' class='bbc_url' title='External link' rel='nofollow external'>http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
   MsgBox(64, @UserName, "Attached sent!", 5)
   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)
   Return
   FileDelete($FilePath)
EndFunc
; The UDF

This might help your smtp mailing as well.

Call() function inserted before running _INetSmtpMailCom:

Call("_INetSmtpMailCom")

And I use the FileDelete() to remove file after sending. All is well and running.:)

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

THe issue I was having was I was trying to send mail using my protected gmail account and I did not see any support for TLS in the function that was provided.  I tried all sorts of combos, but when I couldn't get mail to send with tls, I switched cmail.  Does whatever provider you use tls, or did you reduce security settings to allow for script to be able to send messages?

Link to comment
Share on other sites

  • 2 weeks later...

Matt,

Here's the whole code i have that is working:

Func SendClick()
    $FilePath = "D:\Programs\Attachment\" & @UserName & "\"
    Local $hSearch = FileFindFirstFile($FilePath & "*.*")
    $sFileName = FileFindNextFile($hSearch)

   Local $LevelImportance
     If GUICtrlRead($High) = 1 Then
       $LevelImportance = "High"
      EndIf
      If GUICtrlRead($Medium) = 1 Then
       $LevelImportance = "Medium"
      EndIf
      If GUICtrlRead($Low) = 1 Then
       $LevelImportance = "Low"
      EndIf
      Global $VAR_SmtpServer = "My.Domain.com"
      $FromName = "Matt"
      $FromAddress = "EmailAddress1.com"
      $ToAddress = "EmailAddress2.com"
      $Subject = "Subject line"
      $Body = "This is a test email."
      $AttachFiles = $sFileName
      $CcAddress = "EmailAddress3.com"
      $BccAddress = "EmailAddress4.com"
      $Importance = $LevelImportance
      $Username = "" ; Leave it if not neccessary
      $Password = "" ; Leave it if not neccessary
      $IPPort = 25
      $ssl = 0 ; Change from 1 to 0

   Global $oMyRet[2]
   Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
   $rc = _INetSmtpMailCom($VAR_SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
   If @error Then
      MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
   EndIf
   FileDelete($FilePath & $sFileName)
   Call("_INetSmtpMailCom")
EndFunc
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $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])
               ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                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
    If Number($IPPort) = 0 then $IPPort = 25
    $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") = 0 ; Change from 1 to 0
        $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 ("<a href='http://schemas.microsoft.com/cdo/configuration/smtpusessl' class='bbc_url' title='External link' rel='nofollow external'>http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""

;Create Sent items to know if mail was sent successfully.
$sLongMonthName = _DateToMonth(@MON)
$sLongDayName = _DateDayOfWeek(@WDAY)
$xdate = $sLongDayName & ", " & $sLongMonthName & " " & @MDAY & ", " & @YEAR & " " & @HOUR & ":" & @MIN
$ldate = @MON & "," & @MDAY & "," & @YEAR & " " & @HOUR & "," & @MIN & " " & $sLongDayName
$SentItems = @ScriptDir & @UserName & "\Sent items\"

$fSend = _FileCreate($SentItems&@UserName&"_"&$Subject&"_"&$ldate) ; Input 3 is the subject line for easy tracking

$FileSent = $SentItems&@UserName&"_"&$Subject&"_"&$ldate

FileWriteLine($FileSent, "From: "&$Sname1)
FileWriteLine($FileSent, "Sent: "&$xdate&@CRLF)
FileWriteLine($FileSent, "To: "&$ToAddress&@CRLF)
FileWriteLine($FileSent, "Subject: "&$Subject&@CRLF)
FileWriteLine($FileSent, @CRLF)
FileWriteLine($FileSent, GuiCtrlRead($Edit)&@CRLF)

if GuiCtrlRead($High) = "High" Then
   FileWriteLine($FileSent, "Importance: High"&@CRLF)
   elseif GuiCtrlRead($Medium) = "Med" Then
   FileWriteLine($FileSent, "Importance: Med"&@CRLF)
   elseif GuiCtrlRead($Low) = "Low" Then
   FileWriteLine($FileSent, "Importance: Low"&@CRLF)
endif
EndFunc
   ; 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)
   Return
EndFunc

And here's the changes I made from Jos smtp mailing system.

;From:
SmtpServer = "My.Domain.com"

;To:
Global $VAR_SmtpServer = "My.Domain.com"

;Port:
$IPPort = 25

;From:
$ssl = 1

;To:
$ssl = 0

;From:
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

;To:
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0

I also tried doing combos, and I finally came out with this codes with additional changes of values. I can't truly explain to you how it is working in me and not in you. Also, you might consider the security settings and admin rights to allow your script. ^_^ just a tip!

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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...