Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rote - 16 Apr 2008 05:41 GMT
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);

}
Braulio Diez - 16 Apr 2008 07:53 GMT
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();
}

Signature

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

> I'm getting the email address from an excel sheet.
> But i need to send the email to multiple people
[quoted text clipped - 25 lines]
>
> }
Eliyahu Goldin - 16 Apr 2008 09:40 GMT
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();
}

Signature

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

> 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
[quoted text clipped - 39 lines]
>>
>> }
rote - 16 Apr 2008 10:34 GMT
I'm getting multiple duplicate records using ur code?
any ideas

> This code will always produce only the last email. It can be a bit
> corrected as:
[quoted text clipped - 50 lines]
>>>
>>> }
rote - 16 Apr 2008 09:56 GMT
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

> 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
[quoted text clipped - 39 lines]
>>
>> }
Mark Rae [MVP] - 16 Apr 2008 10:47 GMT
> Response.Write(smail);

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

Signature

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

rote - 16 Apr 2008 10:58 GMT
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]" <mark@markNOSPAMrae.net> wrote in message
news:eusljb6nIHA.5836@TK2MSFTNGP04.phx.gbl...

>> Response.Write(smail);
>
> Response.Write(smail.TrimEnd(';'));
Mark Rae [MVP] - 16 Apr 2008 11:12 GMT
> Error
> The specified string is not in the form required for an e-mail address.
[quoted text clipped - 4 lines]
>
> 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

Signature

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

rote - 17 Apr 2008 00:45 GMT
Thanks but when i do that i get error:
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses

>> Error
>> The specified string is not in the form required for an e-mail address.
[quoted text clipped - 13 lines]
>
> http://www.systemnetmail.com/faq/3.2.3.aspx
rote - 17 Apr 2008 03:14 GMT
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

> Thanks but when i do that i get error:
> The parameter 'addresses' cannot be an empty string.
[quoted text clipped - 17 lines]
>>
>> http://www.systemnetmail.com/faq/3.2.3.aspx
Mark Rae [MVP] - 17 Apr 2008 10:00 GMT
>>>> Any ideas this is driving me nuts
>>>
[quoted text clipped - 16 lines]
> 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...

Signature

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

Eliyahu Goldin - 16 Apr 2008 11:02 GMT
Fantastic.Never paid attention to this method.

Signature

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

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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.