Sending HTML Email to Multiple Recipients

Discussion in 'C#' started by ggrech, Mar 10, 2010.

  1. #1
    I am trying to create a web form to email a HTML newsletter to the visitors freinds.

    I have created a loop (For i = 1 to 5) with the recipients name stored in variables ToName1, ToName2, ...... ToName5

    What is the syntax to use the variable ToName with the number i

    ie htmlbody = "<html><body> Hello" & ToName + i & "</body></html>
     
    ggrech, Mar 10, 2010 IP
  2. bibinsmk

    bibinsmk Active Member

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    You can use Arryas for this concept. You can store the to name in Array Fields and you can access it using Index Number.
     
    bibinsmk, Mar 11, 2010 IP
  3. RoyalFlushed

    RoyalFlushed Peon

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    bibinsmk is right. It is not possible to call variables dynamically the way your example is showing. Your suggested example "adds" 1 to the recipients name...

    A simple way is just concatinate the recipients and perform a split, like this :

    Recipients = ToName1 & ";" & ToName2 & ";" & ToName3 etc...

    Then :

    For RecipientNr = 0 To Recipients.Split(";").length - 1
    htmlbody = "<html><body> Hello" & Recipients(RecipientNr) & "</body></html>"
    Next


    I hope this helps!

    Good luck
     
    RoyalFlushed, Mar 19, 2010 IP
  4. webmasterforums

    webmasterforums Peon

    Messages:
    96
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    1) create one HTML document that u want ro send to one or many recepient.
    i.e <html><body> Hello , {ToName} </body></html>
    2) create a class containig the method to send email. pass Email address and Toname Variables as argument to that method.
    another method that will be used to read that file you created in step one and will return Sting. pass file name as an string argument.
    2.1)System.IO.StreamReader varibleofStreamReader= System.IO.File.OpenText("../HTML file path")
    2.2) take another string variable(i.e. fileRead) assign it with varibleofStreamReader.ReadToEnd();
    2.3) return fileRead.
    Now use this string in Email class.
    2.4) make object MailAsString = ReadFile("../path of the HTML file"); 2.5) replacement in HTML file string:- MailAsString = MessageString.ToString().Replace("{Name}", toNameArgument);
    3) from front end code call this Emailsending method, and pass name of rcepeint.


    You can use loop for the no. of recepients u want to send mail.

    BEST OF LUCK... :)
     
    webmasterforums, Apr 5, 2010 IP
  5. prithwirajsaha83

    prithwirajsaha83 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    just add the names in bcc in headers

    $headers .= 'Bcc: ' . "\r\n";
    that way it will be easy and you dont have execute the email script everytime the loop goes. will be faster just create the Bcc string in a loop and execute only one mail statement

    for more html mail creating guideline

    http://www.knowledge-transfers.com/it/how-to-write-a-html-newsletter
     
    prithwirajsaha83, May 19, 2010 IP