473,395 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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() + ";" + "<br>";

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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}
Jun 27 '08 #1
11 1726
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() + ";" + "<br>";

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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}
Jun 27 '08 #2
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" <br**************@yahoo.eswrote in message
news:23**********************************@microsof t.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() + ";" + "<br>";

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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}

Jun 27 '08 #3
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" <br**************@yahoo.eswrote in message
news:23**********************************@microsof t.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() + ";" + "<br>";

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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}

Jun 27 '08 #4
I'm getting multiple duplicate records using ur code?
any ideas

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ef**************@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" <br**************@yahoo.eswrote in message
news:23**********************************@microsof t.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() + ";" + "<br>";

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

//mail.To.Add(smail);

//this.Label1.Text = smail;

Response.Write(smail);

}


Jun 27 '08 #5
"rote" <na********@hotmail.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
Response.Write(smail);
Response.Write(smail.TrimEnd(';'));
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #6
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]" <ma**@markNOSPAMrae.netwrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
>Response.Write(smail);

Response.Write(smail.TrimEnd(';'));
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #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]" <ma**@markNOSPAMrae.netwrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
>Response.Write(smail);

Response.Write(smail.TrimEnd(';'));
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #8
"rote" <na********@hotmail.comwrote in message
news:%2****************@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

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

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:%2****************@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

Jun 27 '08 #10
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" <na********@hotmail.comwrote in message
news:ua**************@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]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>"rote" <na********@hotmail.comwrote in message
news:%2****************@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


Jun 27 '08 #11
"rote" <na********@hotmail.comwrote in message
news:u1**************@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

Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
4
by: Nathan Sokalski | last post by:
I have a form which will be processed by being sent to an ASP page. I would like the ASP page to take the data from the Request.QueryString (which I know how to do) and format it so I can have it...
2
by: Jim | last post by:
im using asp.net, C# to enter data into a table in sql server...however im getting this error: Input string was not in a correct format. Description: An unhandled exception occurred during the...
1
by: Emmanuel | last post by:
hi, i want to make a tool which automates email replies. How can i include the original message body in my reply using the same format as a normal email client would do, in both html and text...
7
by: Susan Bricker | last post by:
I would like to generate a report (I have the report working already) using MS/ACCESS 2000 and then have the ability to send the report as an email attachment to my colleagues. I have looked...
2
by: Rich | last post by:
Hello, I need to send an automated email message from my application (vb2005) - using system.net.mail. What I need to do to the message is to format the text, like underlining, bolding,...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: arial | last post by:
Hi all, I am getting this error message and I don't know why? Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web...
3
by: shansivamani | last post by:
using SMTP to send email. is there any settings need to be configured apart from Host name and Port, while sending emails using SMTPClient in .Net? when i try to send mail to ids which has only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.