how to get the correct email format when sending email using sqldatareader

Discussion in 'ASP .Net' started by rote, Apr 16, 2008.

  1. rote

    rote Guest

    I'm getting the email address from an excel sheet.
    But i need to send the email to multiple people
    When printing the below i get
    ;;;

    But i want ;;

    i don't need the extra semicolon

    Thanks

    code below
    ------

    while (oledr.Read())

    {

    smail = oledr[0].ToString() + ";" + "<br>";



    //smail += oledr[0].ToString() & ";";

    //mail.To.Add(smail);

    //this.Label1.Text = smail;

    Response.Write(smail);

    }
     
    rote, Apr 16, 2008
    #1
    1. Advertising

  2. rote

    Braulio Diez Guest

    RE: how to get the correct email format when sending email using sqlda

    Well, here you have a work around (it could be better coded, but this will
    work for you), just add the semicolon before and in the first ocurrence don't
    do the concat:

    bool firstTime = true;

    while (oledr.Read())
    {
    smail ="";
    if(!firstTime) smail = ";"
    smail += oledr[0].ToString();
    }

    --
    /// ------------------------------
    /// Braulio Diez
    ///
    /// http://www.tipsdotnet.com
    /// ------------------------------




    "rote" wrote:

    > I'm getting the email address from an excel sheet.
    > But i need to send the email to multiple people
    > When printing the below i get
    > ;;;
    >
    > But i want ;;
    >
    > i don't need the extra semicolon
    >
    > Thanks
    >
    > code below
    > ------
    >
    > while (oledr.Read())
    >
    > {
    >
    > smail = oledr[0].ToString() + ";" + "<br>";
    >
    >
    >
    > //smail += oledr[0].ToString() & ";";
    >
    > //mail.To.Add(smail);
    >
    > //this.Label1.Text = smail;
    >
    > Response.Write(smail);
    >
    > }
    >
    >
    >
     
    Braulio Diez, Apr 16, 2008
    #2
    1. Advertising

  3. Re: how to get the correct email format when sending email using sqlda

    This code will always produce only the last email. It can be a bit corrected
    as:

    smail ="";
    while (oledr.Read())
    {
    if(smail.Length > 0) smail += ";"
    smail += oledr[0].ToString();
    }



    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Braulio Diez" <> wrote in message
    news:...
    > Well, here you have a work around (it could be better coded, but this will
    > work for you), just add the semicolon before and in the first ocurrence
    > don't
    > do the concat:
    >
    > bool firstTime = true;
    >
    > while (oledr.Read())
    > {
    > smail ="";
    > if(!firstTime) smail = ";"
    > smail += oledr[0].ToString();
    > }
    >
    > --
    > /// ------------------------------
    > /// Braulio Diez
    > ///
    > /// http://www.tipsdotnet.com
    > /// ------------------------------
    >
    >
    >
    >
    > "rote" wrote:
    >
    >> I'm getting the email address from an excel sheet.
    >> But i need to send the email to multiple people
    >> When printing the below i get
    >> ;;;
    >>
    >> But i want ;;
    >>
    >> i don't need the extra semicolon
    >>
    >> Thanks
    >>
    >> code below
    >> ------
    >>
    >> while (oledr.Read())
    >>
    >> {
    >>
    >> smail = oledr[0].ToString() + ";" + "<br>";
    >>
    >>
    >>
    >> //smail += oledr[0].ToString() & ";";
    >>
    >> //mail.To.Add(smail);
    >>
    >> //this.Label1.Text = smail;
    >>
    >> Response.Write(smail);
    >>
    >> }
    >>
    >>
    >>
     
    Eliyahu Goldin, Apr 16, 2008
    #3
  4. rote

    rote Guest

    Re: how to get the correct email format when sending email using sqlda

    Thanks but
    Tried what you suggested like this
    bool firstTime = true;

    while (oledr.Read())

    {

    string smail;

    smail = "";

    if (!firstTime)smail = ";";

    //smail = oledr[0].ToString();

    smail += oledr[0].ToString();


    //mail.To.Add(smail);

    Response.Write(smail);

    }

    But didn't solve the problem

    "Braulio Diez" <> wrote in message
    news:...
    > Well, here you have a work around (it could be better coded, but this will
    > work for you), just add the semicolon before and in the first ocurrence
    > don't
    > do the concat:
    >
    > bool firstTime = true;
    >
    > while (oledr.Read())
    > {
    > smail ="";
    > if(!firstTime) smail = ";"
    > smail += oledr[0].ToString();
    > }
    >
    > --
    > /// ------------------------------
    > /// Braulio Diez
    > ///
    > /// http://www.tipsdotnet.com
    > /// ------------------------------
    >
    >
    >
    >
    > "rote" wrote:
    >
    >> I'm getting the email address from an excel sheet.
    >> But i need to send the email to multiple people
    >> When printing the below i get
    >> ;;;
    >>
    >> But i want ;;
    >>
    >> i don't need the extra semicolon
    >>
    >> Thanks
    >>
    >> code below
    >> ------
    >>
    >> while (oledr.Read())
    >>
    >> {
    >>
    >> smail = oledr[0].ToString() + ";" + "<br>";
    >>
    >>
    >>
    >> //smail += oledr[0].ToString() & ";";
    >>
    >> //mail.To.Add(smail);
    >>
    >> //this.Label1.Text = smail;
    >>
    >> Response.Write(smail);
    >>
    >> }
    >>
    >>
    >>
     
    rote, Apr 16, 2008
    #4
  5. rote

    rote Guest

    Re: how to get the correct email format when sending email using sqlda

    I'm getting multiple duplicate records using ur code?
    any ideas

    "Eliyahu Goldin" <> wrote in
    message news:...
    > This code will always produce only the last email. It can be a bit
    > corrected as:
    >
    > smail ="";
    > while (oledr.Read())
    > {
    > if(smail.Length > 0) smail += ";"
    > smail += oledr[0].ToString();
    > }
    >
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Braulio Diez" <> wrote in message
    > news:...
    >> Well, here you have a work around (it could be better coded, but this
    >> will
    >> work for you), just add the semicolon before and in the first ocurrence
    >> don't
    >> do the concat:
    >>
    >> bool firstTime = true;
    >>
    >> while (oledr.Read())
    >> {
    >> smail ="";
    >> if(!firstTime) smail = ";"
    >> smail += oledr[0].ToString();
    >> }
    >>
    >> --
    >> /// ------------------------------
    >> /// Braulio Diez
    >> ///
    >> /// http://www.tipsdotnet.com
    >> /// ------------------------------
    >>
    >>
    >>
    >>
    >> "rote" wrote:
    >>
    >>> I'm getting the email address from an excel sheet.
    >>> But i need to send the email to multiple people
    >>> When printing the below i get
    >>> ;;;
    >>>
    >>> But i want ;;
    >>>
    >>> i don't need the extra semicolon
    >>>
    >>> Thanks
    >>>
    >>> code below
    >>> ------
    >>>
    >>> while (oledr.Read())
    >>>
    >>> {
    >>>
    >>> smail = oledr[0].ToString() + ";" + "<br>";
    >>>
    >>>
    >>>
    >>> //smail += oledr[0].ToString() & ";";
    >>>
    >>> //mail.To.Add(smail);
    >>>
    >>> //this.Label1.Text = smail;
    >>>
    >>> Response.Write(smail);
    >>>
    >>> }
    >>>
    >>>
    >>>

    >
    >
     
    rote, Apr 16, 2008
    #5
  6. rote

    rote Guest

    Error
    The specified string is not in the form required for an e-mail address.
    is it "; "or ", "
    tried all with no success
    Using
    using System.Net.Mail;

    Anu ideas this is driving me nuts

    Thanks Mark

    [MVP]" <> wrote in message
    news:...
    > "rote" <> wrote in message
    > news:...
    >
    >> Response.Write(smail);

    >
    > Response.Write(smail.TrimEnd(';'));
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    rote, Apr 16, 2008
    #6
  7. Fantastic.Never paid attention to this method.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "rote" <> wrote in message
    > news:...
    >
    >> Response.Write(smail);

    >
    > Response.Write(smail.TrimEnd(';'));
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Eliyahu Goldin, Apr 16, 2008
    #7
  8. rote

    rote Guest

    Thanks but when i do that i get error:
    The parameter 'addresses' cannot be an empty string.
    Parameter name: addresses

    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "rote" <> wrote in message
    > news:%...
    >
    >> Error
    >> The specified string is not in the form required for an e-mail address.
    >> is it "; "or ", "
    >> tried all with no success
    >> Using
    >> using System.Net.Mail;
    >>
    >> Any ideas this is driving me nuts

    >
    > Oh right - now I see what you're trying to do...
    >
    > while (oledr.Read())
    > {
    > mail.To.Add(oledr[0].ToString());
    > }
    >
    > http://www.systemnetmail.com/faq/3.2.3.aspx
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    rote, Apr 17, 2008
    #8
  9. rote

    rote Guest

    Actually got it to work.
    This is very confusing between System.Web.Mail and System.Net.
    I remembered when using System.Web.Mail i had to include a semi colon or
    comma
    But it seems System.Net. doesn't need it .
    Does it add it automatically i need to get thhis right.
    Thanks


    "rote" <> wrote in message
    news:...
    > Thanks but when i do that i get error:
    > The parameter 'addresses' cannot be an empty string.
    > Parameter name: addresses
    >
    > "Mark Rae [MVP]" <> wrote in message
    > news:%...
    >> "rote" <> wrote in message
    >> news:%...
    >>
    >>> Error
    >>> The specified string is not in the form required for an e-mail address.
    >>> is it "; "or ", "
    >>> tried all with no success
    >>> Using
    >>> using System.Net.Mail;
    >>>
    >>> Any ideas this is driving me nuts

    >>
    >> Oh right - now I see what you're trying to do...
    >>
    >> while (oledr.Read())
    >> {
    >> mail.To.Add(oledr[0].ToString());
    >> }
    >>
    >> http://www.systemnetmail.com/faq/3.2.3.aspx
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net

    >
    >
     
    rote, Apr 17, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    2
    Views:
    585
    William \(Bill\) Vaughn
    Oct 29, 2003
  2. =?Utf-8?B?YmlkbGxj?=

    problem sending email in html format

    =?Utf-8?B?YmlkbGxj?=, Sep 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    546
    Hans Kesting
    Sep 28, 2004
  3. =?Utf-8?B?amFrdWIuYmF1ZXI=?=

    Sending text format email using SmtpMail

    =?Utf-8?B?amFrdWIuYmF1ZXI=?=, Sep 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    =?Utf-8?B?amFrdWIuYmF1ZXI=?=
    Sep 14, 2005
  4. =?Utf-8?B?ZGhucml2ZXJzaWRl?=

    can i get a list of field names in a SqlDataReader ?

    =?Utf-8?B?ZGhucml2ZXJzaWRl?=, Sep 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    34,883
    ihaathi
    Dec 31, 2007
  5. Luke
    Replies:
    2
    Views:
    4,728
    Nigel Wade
    Mar 15, 2007
Loading...

Share This Page