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

R

rote

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
(e-mail address removed);[email protected];;

But i want (e-mail address removed);[email protected];

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);

}
 
B

Braulio Diez

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
/// ------------------------------
 
E

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 said:
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 said:
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
(e-mail address removed);[email protected];;

But i want (e-mail address removed);[email protected];

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);

}
 
R

rote

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 said:
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 said:
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
(e-mail address removed);[email protected];;

But i want (e-mail address removed);[email protected];

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);

}
 
R

rote

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

Eliyahu Goldin said:
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 said:
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 said:
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
(e-mail address removed);[email protected];;

But i want (e-mail address removed);[email protected];

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);

}
 
R

rote

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
 
R

rote

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

Mark Rae said:
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
 
R

rote

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 said:
Thanks but when i do that i get error:
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses

Mark Rae said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top