Send an email with AutoIt

Christopher Peterson picture Christopher Peterson · Oct 12, 2010 · Viewed 30.7k times · Source

How to send an email with AutoIt? Just need a clean example and explanation, containing:

  • to
  • from
  • subject
  • message

Answer

Copas picture Copas · Oct 13, 2010

There are two main ways to go with built in code, _INetMail() or _INetSmtpMail()

Below are the simple code examples from the help file. If you have any specific questions about how they work or how to implement them not covered by the help file please leave a comment.

In my opinion the _INetSmtpMail() route is more reasonable. Below is some example code of it.

#include <INet.au3>

$s_SmtpServer = "mysmtpserver.com.au"
$s_FromName = "My Name"
$s_FromAddress = "From eMail Address"
$s_ToAddress = "To eMail Address"
$s_Subject = "My Test UDF"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf

The _INetMail() method using the built in mail client registered with windows.

#include <INet.au3>

$Address = InputBox('Address', 'Enter the E-Mail address to send message to')
$Subject = InputBox('Subject', 'Enter a subject for the E-Mail')
$Body = InputBox('Body', 'Enter the body (message) of the E-Mail')
MsgBox(0,'E-Mail has been opened','The E-Mail has been opened and process identifier for the E-Mail client is ' & _INetMail($address, $subject, $body))