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

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

am 16.04.2008 06:41:37 von naijacoder

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
a@a.com;b@b.com;;

But i want a@a.com;b@b.com;

i don't need the extra semicolon

Thanks

code below
------

while (oledr.Read())

{

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



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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}

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

am 16.04.2008 08:53:00 von braulio121NOSPAM

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
> a@a.com;b@b.com;;
>
> But i want a@a.com;b@b.com;
>
> i don't need the extra semicolon
>
> Thanks
>
> code below
> ------
>
> while (oledr.Read())
>
> {
>
> smail = oledr[0].ToString() + ";" + "
";
>
>
>
> //smail += oledr[0].ToString() & ";";
>
> //mail.To.Add(smail);
>
> //this.Label1.Text = smail;
>
> Response.Write(smail);
>
> }
>
>
>

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

am 16.04.2008 10:40:15 von Eliyahu Goldin

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:23ABCE93-79BB-4B4B-B95A-B5ED55E30B16@microsoft.com...
> 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
>> a@a.com;b@b.com;;
>>
>> But i want a@a.com;b@b.com;
>>
>> i don't need the extra semicolon
>>
>> Thanks
>>
>> code below
>> ------
>>
>> while (oledr.Read())
>>
>> {
>>
>> smail = oledr[0].ToString() + ";" + "
";
>>
>>
>>
>> //smail += oledr[0].ToString() & ";";
>>
>> //mail.To.Add(smail);
>>
>> //this.Label1.Text = smail;
>>
>> Response.Write(smail);
>>
>> }
>>
>>
>>

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

am 16.04.2008 10:56:50 von naijacoder

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:23ABCE93-79BB-4B4B-B95A-B5ED55E30B16@microsoft.com...
> 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
>> a@a.com;b@b.com;;
>>
>> But i want a@a.com;b@b.com;
>>
>> i don't need the extra semicolon
>>
>> Thanks
>>
>> code below
>> ------
>>
>> while (oledr.Read())
>>
>> {
>>
>> smail = oledr[0].ToString() + ";" + "
";
>>
>>
>>
>> //smail += oledr[0].ToString() & ";";
>>
>> //mail.To.Add(smail);
>>
>> //this.Label1.Text = smail;
>>
>> Response.Write(smail);
>>
>> }
>>
>>
>>

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

am 16.04.2008 11:34:37 von naijacoder

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

"Eliyahu Goldin" wrote in
message news:efC6z25nIHA.3428@TK2MSFTNGP02.phx.gbl...
> 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:23ABCE93-79BB-4B4B-B95A-B5ED55E30B16@microsoft.com...
>> 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
>>> a@a.com;b@b.com;;
>>>
>>> But i want a@a.com;b@b.com;
>>>
>>> i don't need the extra semicolon
>>>
>>> Thanks
>>>
>>> code below
>>> ------
>>>
>>> while (oledr.Read())
>>>
>>> {
>>>
>>> smail = oledr[0].ToString() + ";" + "
";
>>>
>>>
>>>
>>> //smail += oledr[0].ToString() & ";";
>>>
>>> //mail.To.Add(smail);
>>>
>>> //this.Label1.Text = smail;
>>>
>>> Response.Write(smail);
>>>
>>> }
>>>
>>>
>>>
>
>

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

am 16.04.2008 11:47:31 von mark

"rote" wrote in message
news:uBr0dw3nIHA.3532@TK2MSFTNGP03.phx.gbl...

> Response.Write(smail);

Response.Write(smail.TrimEnd(';'));


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

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

am 16.04.2008 11:58:22 von naijacoder

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:eusljb6nIHA.5836@TK2MSFTNGP04.phx.gbl...
> "rote" wrote in message
> news:uBr0dw3nIHA.3532@TK2MSFTNGP03.phx.gbl...
>
>> Response.Write(smail);
>
> Response.Write(smail.TrimEnd(';'));
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

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

am 16.04.2008 12:02:39 von Eliyahu Goldin

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:eusljb6nIHA.5836@TK2MSFTNGP04.phx.gbl...
> "rote" wrote in message
> news:uBr0dw3nIHA.3532@TK2MSFTNGP03.phx.gbl...
>
>> Response.Write(smail);
>
> Response.Write(smail.TrimEnd(';'));
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

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

am 16.04.2008 12:12:49 von mark

"rote" wrote in message
news:%237sZeh6nIHA.2188@TK2MSFTNGP04.phx.gbl...

> 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

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

am 17.04.2008 01:45:42 von naijacoder

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:%23unJsp6nIHA.4672@TK2MSFTNGP05.phx.gbl...
> "rote" wrote in message
> news:%237sZeh6nIHA.2188@TK2MSFTNGP04.phx.gbl...
>
>> 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

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

am 17.04.2008 04:14:48 von naijacoder

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:uavDyvBoIHA.4308@TK2MSFTNGP06.phx.gbl...
> 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:%23unJsp6nIHA.4672@TK2MSFTNGP05.phx.gbl...
>> "rote" wrote in message
>> news:%237sZeh6nIHA.2188@TK2MSFTNGP04.phx.gbl...
>>
>>> 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
>
>

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

am 17.04.2008 11:00:40 von mark

"rote" wrote in message
news:u1aHGDDoIHA.2064@TK2MSFTNGP05.phx.gbl...

>>>> 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
>>
>> Thanks but when i do that i get error:
>> The parameter 'addresses' cannot be an empty string.
>> Parameter name: addresses
>
> Actually got it to work.
> This is very confusing between System.Web.Mail and System.Net.Mail
> I remembered when using System.Web.Mail i had to include a semi colon or
> comma
> But it seems System.Net.Mail doesn't need it .

That's right. In System.Net.Mail, the .To, .Cc and .Bcc properties are
collections, not strings, so they don't require anything to "separate" the
individual addresses... That's why the code I gave you above doesn't include
a semi-colon at the end of the addresses...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net