Jump to content

Emailing in Autoit?


Recommended Posts

I am making Email Client software in autoit and here is the mailer (I found it on example scripts and I modified it a bit to fit my needs)

#Include <file.au3>
$s_SmtpServer = "smtp.gmail.com"              
$s_FromName = "Name"                      
$s_FromAddress = "xyz@gmail.com"
$s_ToAddress = "zyx@gmail.com"   
$s_Subject = "Subject"                 
$as_Body = "xyz"                            
$s_AttachFiles = ""                   
$s_CcAddress = ""       
$s_BccAddress = ""     
$s_Username = "xyz"                 
$s_Password = "password"                  
$IPPort=465                         
$ssl=1                               

Global $oMyRet[2]

$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)
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
    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
    $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
    EndFunc

I made it to read the passwords and necessary information from .ini file. But here is the problem, it successfully sends the Email while connected but when the user isn't connected to the internet, it pops error window. I want it to try to resend the email every 30 seconds until it succesfully sends the email. I have tried using Do...Until loops but no luck.

Thanx in advance

There are 10 kinds of people, those who understand me and those who don't.
Link to comment
Share on other sites

  • Developers

You need to add the ComEvent Error Handler to avoid any error popping up and then in a loop keep trying to resent until successful.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Could you discribe it a bit more

The Examples thread where I have posted the _INetSmtpMailCom() UDF has most of it in it.

You only need to add the loop.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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