Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can i put semicomma seperated emailid in To using System.Net.Mail namespace

Can i put semicomma seperated emailid in To using System.Net.Mail namespace

Scheduled Pinned Locked Moved ASP.NET
helpcsharpcom
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krishnraj
    wrote on last edited by
    #1

    Hi all, I make one application in which i have one requirement that, i have to put multiple emailids with semicomma seperated like - "abc1@abc.com; abc2@abc.com; abc3@abc.com; ..." but its give me an error when i assign it in "To"!!!! When i put single emailid then it don't gives any error... Need some suggesion to solve this issue...

    Krishnraj

    C 1 Reply Last reply
    0
    • K Krishnraj

      Hi all, I make one application in which i have one requirement that, i have to put multiple emailids with semicomma seperated like - "abc1@abc.com; abc2@abc.com; abc3@abc.com; ..." but its give me an error when i assign it in "To"!!!! When i put single emailid then it don't gives any error... Need some suggesion to solve this issue...

      Krishnraj

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You need to write some code. Sorry about that. You need to turn your list of emails into a collection of addresses which get applied to the to and the bcc, I guess.

      Christian Graus Driven to the arms of OSX by Vista.

      K 1 Reply Last reply
      0
      • C Christian Graus

        You need to write some code. Sorry about that. You need to turn your list of emails into a collection of addresses which get applied to the to and the bcc, I guess.

        Christian Graus Driven to the arms of OSX by Vista.

        K Offline
        K Offline
        Krishnraj
        wrote on last edited by
        #3

        Hi Christian, First-of-all thanks for replying... there is no issue to put the code and here is my code...

        Dim Strsmtp As New System.Net.Mail.MailMessage
        ' MailFrom and MailTo come from the database
        Dim from As New System.Net.Mail.MailAddress(objReader("MailFrom").ToString())

        ' Here i Put hard code emailids
        Dim toList As New System.Net.Mail.MailAddress("abc1@abc.com;abc2@abc.com")
        Strsmtp.From = from
        Strsmtp.To.Add(toList)

        Strsmtp.Subject = "Hi"
        Strsmtp.IsBodyHtml = True
        Strsmtp.Headers.Add("Content-Type", objReader("MailContentType"))
        Strsmtp.Headers.Add("Reply-To", objReader("MailReplyTo"))
        Strsmtp.Body = "Test"
        Dim sp As New System.Net.Mail.SmtpClient()
        sp.Send(Strsmtp)

        and when i put the single emailid, then it gives different error that - Host Name is not specified. But i already specified host name in my web.config file. Here is the code..

        <system.net>
        <mailSettings>
        <smtp>
        <network host="localhost" />
        </smtp>
        </mailSettings>
        </system.net>

        as i work in my local pc, so i write "localhost"... Now i don't understand what i have to do???:confused:

        Krishnraj

        C 1 Reply Last reply
        0
        • K Krishnraj

          Hi Christian, First-of-all thanks for replying... there is no issue to put the code and here is my code...

          Dim Strsmtp As New System.Net.Mail.MailMessage
          ' MailFrom and MailTo come from the database
          Dim from As New System.Net.Mail.MailAddress(objReader("MailFrom").ToString())

          ' Here i Put hard code emailids
          Dim toList As New System.Net.Mail.MailAddress("abc1@abc.com;abc2@abc.com")
          Strsmtp.From = from
          Strsmtp.To.Add(toList)

          Strsmtp.Subject = "Hi"
          Strsmtp.IsBodyHtml = True
          Strsmtp.Headers.Add("Content-Type", objReader("MailContentType"))
          Strsmtp.Headers.Add("Reply-To", objReader("MailReplyTo"))
          Strsmtp.Body = "Test"
          Dim sp As New System.Net.Mail.SmtpClient()
          sp.Send(Strsmtp)

          and when i put the single emailid, then it gives different error that - Host Name is not specified. But i already specified host name in my web.config file. Here is the code..

          <system.net>
          <mailSettings>
          <smtp>
          <network host="localhost" />
          </smtp>
          </mailSettings>
          </system.net>

          as i work in my local pc, so i write "localhost"... Now i don't understand what i have to do???:confused:

          Krishnraj

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          The issue is that the object you call toList is not a list but a single object. You must add a separate MailAddress object for each address in your string.

          *Developer Day Scotland - Free community conference Delegate Registration Open

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups