Jump to content

Sending to multiple receipients using _INetSmtpMail?


 Share

Recommended Posts

Hi!

I very much like _INetSmtpMail UDF, but I can't seem to mail to multiple receipients. I tried concatenating adresses separated by ',', then I tried quoting and doublequoting receipients list, but it keeps sending to "receipients list"@smtp....

While testing smtp protocol on smtp server I figured it out, the _INetSmtpMail must be using very basic approach while communicating with smtp server.

It looks like I'll have to design smarter smtp client....

Cheers,

Bostjan

Edit: added second and third paragraph to the post...

Edited by BoskoBuha
Link to comment
Share on other sites

Have you tried to separate the recipients by ";" (Semikolon)? See this post.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Have you tried to separate the recipients by ";" (Semikolon)? See this post.

Just did.

Error I'm getting back is 52. I also tried quoting the whole string, but all I get back is undelievered mail (email addresses, hostnames and IPs are anonimised!):

<"receipient@email; sender"@email>: host hostname [host IP]

said: 554 5.7.1 <receipient@email; sender@email>: Relay access denied

(in reply to RCPT TO command)

Reporting-MTA: dns; smtp.server

X-Postfix-Queue-ID: 00ADE70042

X-Postfix-Sender: rfc822; sender@email

Arrival-Date: Fri, 11 Sep 2009 14:10:49 +0200 (CEST)

Final-Recipient: rfc822; "receipient@email; sender"@email

Original-Recipient: rfc822; "receipient@email; sender"@email

Action: failed

Status: 5.7.1

Remote-MTA: dns; hostname

Diagnostic-Code: smtp; 554 5.7.1 <receipient@email; sender@email>: Relay access denied

--------------------------------------------------------------------------------------

Subject: Subject

From: Sender Name <sender@email>

Date: Fri, 11 Sept 2009 14:10:53 (+0100)

To: <"receipient@email; sender@email"@smtp.server>

body

If Not _INetSmtpMail( "smtp.server", "Sender Name", "sender@email", '"receipient@email; sender@email"', "Subject", $aBody, "ehlo domain.name", -1) Then
        Switch @error
            Case 1
                MsgBox(0,"","_InetSmtpMail error "&@error&": Invalid Parameters!")
            Case 2
                MsgBox(0,"","_InetSmtpMail error "&@error&": Unable to start TCP!")
            Case 3
                MsgBox(0,"","_InetSmtpMail error "&@error&": Unable to resolve IP!")
            Case 4
                MsgBox(0,"","_InetSmtpMail error "&@error&": Unable to create socket!")
            Case 50 to 59
                MsgBox(0,"","_InetSmtpMail error "&@error&": Cannot open SMTP session!"&@CRLF &"5x indicates the index number of last command issued to the SMTP server.")
            Case 500 to 509
                MsgBox(0,"","_InetSmtpMail error "&@error&": Cannot send body!"&@CRLF&"50x indicates the line number of $as_Body (first line is 0).")
            Case 5000
                MsgBox(0,"","_InetSmtpMail error "&@error&": Cannot close SMTP session!")
        EndSwitch
EndIf
Link to comment
Share on other sites

  • 8 years later...

I realize that this is a very old thread but I do have a solution - an additional function to the Inet.au3 library.  You must include the Array.au3 library at the beginning of the Inet.au3 library - that is, add the following line to the other include lines at the top of the file:

#include "Array.au3"

 

Then add this adaptation of _INetSmtpMail, which I am calling _INetSmtpMails:

; #FUNCTION# ====================================================================================================================
; Author ........: Asimzameer, Walkabout
; Modified.......: Woody Barrett on 27 Nov 2017
; ===============================================================================================================================
Func _INetSmtpMails($sSMTPServer, $sFromName, $sFromAddress, $sToAddress, $sSubject = "", $aBody = "", $sEHLO = "", $sFirst = "", $bTrace = 0)
    Local $i = 0
    Local $j = 0

    If $sSMTPServer = "" Or $sFromAddress = "" Or $sToAddress[0] = "" Or $sFromName = "" Or StringLen($sFromName) > 256 Then Return SetError(1, 0, 0)
    If $sEHLO = "" Then $sEHLO = @ComputerName

    If TCPStartup() = 0 Then Return SetError(2, 0, 0)

    Local $s_IPAddress, $i_Count
    If StringRegExp($sSMTPServer, "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$") Then
        $s_IPAddress = $sSMTPServer
    Else
        $s_IPAddress = TCPNameToIP($sSMTPServer)
    EndIf
    If $s_IPAddress = "" Then
        TCPShutdown()
        Return SetError(3, 0, 0)
    EndIf
    Local $vSocket = TCPConnect($s_IPAddress, 25)
    If $vSocket = -1 Then
        TCPShutdown()
        Return SetError(4, 0, 0)
    EndIf

    Local $aSend[2], $aReplyCode[2] ; Return code from SMTP server indicating success
    $aSend[0] = "HELO " & $sEHLO & @CRLF
    If StringLeft($sEHLO, 5) = "EHLO " Then $aSend[0] = $sEHLO & @CRLF
    $aReplyCode[0] = "250"

    $aSend[1] = "MAIL FROM: <" & $sFromAddress & ">" & @CRLF
    $aReplyCode[1] = "250"
    for $i=0 to (UBound($sToAddress) - 1)
        _ArrayAdd($aSend, "RCPT TO: <" & $sToAddress[$i]& ">" & @CRLF)
        _ArrayAdd($aReplyCode, "250")
    Next
    _ArrayAdd($aSend, "DATA" & @CRLF)
    _ArrayAdd($aReplyCode, "354")

    Local $aResult = _Date_Time_GetTimeZoneInformation()
    Local $iBias = -$aResult[1] / 60
    Local $iBiasH = Int($iBias)
    Local $iBiasM = 0
    If $iBiasH <> $iBias Then $iBiasM = Abs($iBias - $iBiasH) * 60
    $iBias = StringFormat(" (%+.2d%.2d)", $iBiasH, $iBiasM)

    _ArrayAdd($aSend, "From:" & $sFromName & "<" & $sFromAddress & ">" & @CRLF)
    $j = UBound($aSend) - 1
    $aSend[$j] &= "To:" & "<" & $sToAddress & ">"
    if UBound($sToAddress) > 1 Then
        for $i=1 to UBound($sToAddress) - 1
            $aSend[$j] &= ";<" & $sToAddress[$i] & ">"
        Next
    EndIf
    $aSend[$j] &= @CRLF & _
        "Subject:" & $sSubject & @CRLF & _
        "Mime-Version: 1.0" & @CRLF & _
        "Date: " & _DateDayOfWeek(@WDAY, 1) & ", " & @MDAY & " " & _DateToMonth(@MON, 1) & " " & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & $iBias & @CRLF & _
        "Content-Type: text/plain; charset=US-ASCII" & @CRLF & @CRLF
    _ArrayAdd($aReplyCode, "")

    _ArrayAdd($aSend, @CRLF & "." & @CRLF)
    _ArrayAdd($aReplyCode, "250")

    ; open stmp session
    If __SmtpSend($vSocket, $aSend[0], $aReplyCode[0], $bTrace, "220", $sFirst) Then Return SetError(50, 0, 0)

    ; send header
    For $i_Count = 1 To UBound($aSend) - 2
        If __SmtpSend($vSocket, $aSend[$i_Count], $aReplyCode[$i_Count], $bTrace) Then Return SetError(50 + $i_Count, 0, 0)
    Next

    ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..)
    For $i_Count = 0 To UBound($aBody) - 1
        ; correct line beginning with a dot
        If StringLeft($aBody[$i_Count], 1) = "." Then $aBody[$i_Count] = "." & $aBody[$i_Count]

        If __SmtpSend($vSocket, $aBody[$i_Count] & @CRLF, "", $bTrace) Then Return SetError(500 + $i_Count, 0, 0)
    Next

    ; close the smtp session
    $i_Count = UBound($aSend) - 1
    If __SmtpSend($vSocket, $aSend[$i_Count], $aReplyCode[$i_Count], $bTrace) Then Return SetError(5000, 0, 0)

    TCPCloseSocket($vSocket)
    TCPShutdown()
    Return 1
EndFunc   ;==>_INetSmtpMails

the $sToAddress parameter is an array in this function so make sure you pass it an array of email address(es) when you call it.

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