Jump to content

Mail To Multiple Addresses


Recommended Posts

Is there a way to have multiple recipients within the $s_ToAddress field within this script?

#include <INet.au3>

$s_SmtpServer = "10.X.X.X"
$s_FromName = "my name"
$s_FromAddress = "myname@sna.com"
$s_ToAddress = "User1@sna.com"
$s_Subject = "My Test SMTP"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email alerts"
$as_Body[1] = "Sent through Auto It"
$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
Link to comment
Share on other sites

  • Moderators

Could have swore you asked this question already: http://www.autoitscript.com/forum/index.ph...ndpost&p=178234

Edit:

This might work, (Untested, but you'll get the idea)

#include <INet.au3>
$ToAddresses = 'Someone1@another.com,Someone2@another.com'
$ToAddresses = StringSplit($ToAddresses, ',')
Local $Body[2] = ['Testing the new email alerts', 'Sent through AutoIt']
_SendMultiple("10.X.X.X", "my name", "myname@sna.com", $ToAddresses, 'Have you heard?', $Body)

Func _SendMultiple($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    If IsArray($s_FromAddress) Then
        For $icount = 1 To UBound($s_FromAddress) - 1
            If _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress[$icount], $s_ToAddress, $s_Subject, $as_Body) Then
                MsgBox(0, "Success!", "Mail sent")
            Else
                MsgBox(0, "Error!", "Mail failed with error code " & @error)
            EndIf
        Next
    Else
        If _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) Then
            MsgBox(0, "Success!", "Mail sent")
        Else
            MsgBox(0, "Error!", "Mail failed with error code " & @error)
        EndIf
    EndIf
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

@mrrlg - did either of these options work, or did you find another alternative?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

When I insert a semi colon that stops the script at that portion of the line and any addresses behind that are not picked up. I tried using a / in front of the ; as an escape and that did not work.

I also tried your second suggestion and the script fails as the $s_ToAddress does not resolve to $s_ToAddresses.

In the end I created a mail group in the server and use that as the email account called for in the script. Now I can notify multiple users using this script.

Link to comment
Share on other sites

When I insert a semi colon that stops the script at that portion of the line and any addresses behind that are not picked up. I tried using a / in front of the ; as an escape and that did not work.

I also tried your second suggestion and the script fails as the $s_ToAddress does not resolve to $s_ToAddresses.

In the end I created a mail group in the server and use that as the email account called for in the script. Now I can notify multiple users using this script.

Did you put the string in quotes as shown by gafrost? The semi-colon is used for comments in AutoIt, so without quotes it is commenting out the rest of the line. With quotes surrounding the string, the semi-colon is included as part of the string.

Link to comment
Share on other sites

I was able to string together multiple addresses within the quotation marks and using the script suggested by SmOke_N and I do get a Successful Mail Sent response. The trouble is, the smtp server does not receive anything when I examine all the queues. My messages are wandering around in LAN cyberspace somewhere. I will keep playing around with the script to see if I can get it to work.

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