Problem sending email to multiple recipients using code - InfoPath Dev
in

InfoPath Dev

Problem sending email to multiple recipients using code

Last post 02-22-2011 10:48 AM by g21cincy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-21-2011 09:51 AM

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Problem sending email to multiple recipients using code

    Here is the code I'm using. It will go through if I just have one email address listed in the toAddress field but gives me an error when I add more. Any help would be greatly appreciated.

    Private Sub SendEmailClassRequest(ByVal Email As Boolean)

    Dim fromAddress As MailAddress = New MailAddress("[email protected]")

    Dim toAddress As MailAddress = New MailAddress("[email protected], [email protected], [email protected], [email protected]")

    Dim msgmail As MailMessage = New MailMessage(fromAddress, toAddress)

    msgmail.Subject = "Subject here"

    msgmail.Body = "Body here"

    Dim client As SmtpClient = New SmtpClient("smptclient") client.Credentials = New System.Net.NetworkCredential("xxxxx", "xxxxxx")

     

    client.Send(msgmail)

    End Sub

  • 02-21-2011 11:48 AM In reply to

    Re: Problem sending email to multiple recipients using code

    Hi! Try using semicolons (;) in the toAddress field instead of commas:

    Private Sub SendEmailClassRequest(ByVal Email As Boolean)

    Dim fromAddress As MailAddress = New MailAddress("[email protected]")

    Dim toAddress As MailAddress = New MailAddress("[email protected]; [email protected]; [email protected]; [email protected]")

    Dim msgmail As MailMessage = New MailMessage(fromAddress, toAddress)

    msgmail.Subject = "Subject here"

    msgmail.Body = "Body here"

    Dim client As SmtpClient = New SmtpClient("smptclient") client.Credentials = New System.Net.NetworkCredential("xxxxx", "xxxxxx")

     

    client.Send(msgmail)

    End Sub

  • 02-21-2011 12:06 PM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Problem sending email to multiple recipients using code

    I get the following error when I add the semicolons as you replied:

    The specified string is not in the form required for an e-mail address

  • 02-22-2011 10:48 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Problem sending email to multiple recipients using code

    I just figured it out.

    Private Sub SendEmailClassRequest(ByVal Email As Boolean)

    Dim fromAddress As MailAddress = New MailAddress("[email protected]")

    Dim toAddress As MailAddress = New MailAddress("[email protected]")

    Dim msgmail As MailMessage = New MailMessage(fromAddress, toAddress)

    msgmail.To.Add("email2@email.com")

    msgmail.To.Add("email3@email.com")

    msgmail.To.Add("[email protected]")

    msgmail.Subject = "Subject here"

    msgmail.Body = "Body here"

    Dim client As SmtpClient = New SmtpClient("smptclient") client.Credentials = New System.Net.NetworkCredential("xxxxx", "xxxxxx")

    client.Send(msgmail)

    End Sub

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.