Sign in to follow this  
Followers 0
mrrlg

Mail To Multiple Addresses

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

try semi-colon between address', i.e.

$s_ToAddress = "User1@sna.com;your_e-mail@my.com"

replace your_e-mail@my.com with the addy you want to send to


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0