0

Hello,

I am having an issue with sending an email message to multiple recipients on a private SMTP server. Currently, my program sends a message to the first recipient listed, but not the second. I am getting the email addresses from a text box right now that is separated like : email1@blah.com;email2@blah.com. Also, I am using a custom Winsock to send the data right now.

        myWinsock.RemoteIP = "127.0.0.1"
        myWinsock.RemotePort = 1000

        Me.Cursor = Cursors.WaitCursor
        lblStatus.Text = "Status: Connecting to server " & txtServer.Text

        recips = Split(txtRecipient.Text, ";") 'Split multiple addresses

        myWinsock.Connect() 'Connect in form load


        Private Sub myWinsock_DataArrival(ByVal sender As SDJWinsock, ByVal BytesTotal As Integer) Handles myWinsock.DataArrival

        Dim intReply As Integer
        Dim strData As String
        Dim strMessage As String
        Dim recipCount As Integer = 0

        myWinsock.GetData(strData)

        intReply = CInt(Microsoft.VisualBasic.Left(strData, 3))

        Select Case intReply
            Case 220
                If Not gblnReceived220 Then
                    gblnReceived220 = True

                    gstrCommand = "HELO " & Mid(txtSender.Text, _
                                                InStr(txtSender.Text, "@") + 1) & _
                                                vbCrLf
                    myWinsock.SendData(gstrCommand)
                    gstrCommand = Microsoft.VisualBasic.Left(gstrCommand, 4)
                End If

            Case 250
                Select Case gstrCommand
                    Case "HELO"
                        gstrCommand = "MAIL FROM: <" &
                            txtSender.Text & ">" & _
                            vbCrLf

                        myWinsock.SendData(gstrCommand)
                        gstrCommand = Microsoft.VisualBasic.Left(gstrCommand, 4)

                    Case "MAIL"
                        gstrCommand = "RCPT TO: <" & recips(recipCount) &
                                          ">" & vbCrLf
                        myWinsock.SendData(gstrCommand)
                        If recipCount = UBound(recips) Then
                            gstrCommand = Microsoft.VisualBasic.Left(gstrCommand, 4)
                        End If
                        recipCount += 1
                    Case "RCPT"
                        gstrCommand = "DATA" & vbCrLf
                        myWinsock.SendData(gstrCommand)
                        gstrCommand = Microsoft.VisualBasic.Left(gstrCommand, 4)

                    Case "DATA"
                        lblStatus.Text = "Status: Mail was successfuly sent."
                        Me.Cursor = Cursors.Default
                        gblnReceived220 = False

                    Case "QUIT"
                        lblStatus.Text = "Status: Connection Closed"
                        myWinsock.Close()
                End Select

            Case 354
                Select Case gstrCommand
                    Case "DATA"
                        strMessage = "DATE: " & Format(Now, "f") & vbCrLf & _
                                     "FROM: " & txtSender.Text & vbCrLf & _
                                     "TO: " & txtRecipient.Text & vbCrLf & _
                                     "SUBJECT: " & txtSubject.Text &
                                     vbCrLf & _
                                     vbCrLf & _
                                     txtMessage.Text & vbCrLf & _
                                     vbCrLf & _
                                     "." & vbCrLf
                        myWinsock.SendData(strMessage)
                End Select

I have also tried to loop through, but was unsuccessful too. Any ideas or thoughts on how I can get the message sent to the second recipient?

2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by G_Waddell
0

Hi,

I can't see any loop in your code...

What I see is the following:
1. You only do anything with the recips array when intReply = 250
2. When you go into that bit of the code, recipCount = 0 (unless changed somewhere else)
3. You build your command then send your data
4. You then check if the is the upper bound of Recips and if it is you alter the command (but you already sent it..)
5. Now you increase the recipCount by one
6. Then the rest of your sub routine is missing so I assume you've finished in which case you never actually do anything with the next recipient, unless you are calling the routine in a loop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.