Showing posts with label addresses. Show all posts
Showing posts with label addresses. Show all posts

Monday, March 26, 2012

System.Net.Mail and Multiple .To() addresses

I'm still milling over if it's a step forward or a step back on this one. Or, if I'm just missing something on it.
Is there a way to specify multiple email addresses in the To line of a message created with the new mail Namespace.
With the old namespace, I could just use address1@dotnet.itags.org.mail.com; address2@dotnet.itags.org.mail.com; address3@dotnet.itags.org.mail.com
This worked great, since it allowed everyone that was in the To line tobe visible, and not require sending 15 emails to the SMTP server, justone, and then it created what it needed to send out to each recipient.Now, I get an error that the recipient email is malformed, and can'tsend it. Know of any way around this?
Dim Msg As New MailMessage
Dim To_Addr As MailAddressCollection = Msg.To
To_Addr.Add(New MailAddress("address1@.mail.com", "Some Person"))
To_Addr.Add(New MailAddress("address2@.mail.com", "Some Other Person"))
To_Addr.Add(New MailAddress("address3@.mail.com")

Muchas Gracias. I'm still trying to get the hang of all of the changes, and my last solution was from-the-hip as it was. Apparently, ASP.NET 2.0 is much less forgiving of from-the-hip programming...
Now, for whatever reason, I've come up against a new error...

Server Error in '/' Application.

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message:BC30516: Overload resolution failed because no accessible 'New' accepts this number of arguments.
Source Error:


Line 637: Dim strStake As String
Line 638:
Line 639: Dim objMessage As New MailMessage
Line 640: Dim emSubject As String
Line 641: Dim emBody As String


The code behind this is is exactly as it shows up there. So, I'm backto confused... if I take out the "New" I get "Not set to Instance of anObject" errors.


I think you need to put () at the end of New Mailmessage()
From the SDK:
Usage

Visual Basic
Dim mailMessage1 As NewMailMessage()


According to Microsoft, the ";" separated [To] adress list string should work - see the SMTP send method at :
http://msdn2.microsoft.com/en-us/library/h1s04he7

No, I get the same error, unfortunately.

System.Net.Mail to address

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
David
strUser = UtilClass.GetUserName(strUser)
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@dotnet.itags.org.myemail.com"
Const FromAddress As String = "me@dotnet.itags.org.myemail.com"
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.
protected void btnSendUpload_Click(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03;Initial
Catalog=CCTS;Persist Security Info=True;User
ID=UserID;Password=Password";
using (SqlConnection connection = new
SqlConnection(constring))
{
connection.Open();
SqlCommand command = new SqlCommand(queryString,
connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string captured = Convert.ToString(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(Your From
Address);
MailAddress to = new MailAddress(captured);
MailMessage msg = new MailMessage(from, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.NewLine + Environment.NewLine;
Attachment attach = new Attachment("\\\\glsdbs03\\d
$\\File\\LaborFile.txt");
msg.Attachments.Add(attach);
mailSvr.Send(msg);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}
I hope this helps
On Nov 21, 4:00 pm, "David C" <dlch...@.lifetimeinc.com> wrote:
> I would like to have an email go to 2 email addresses but when I try it by
> separating with semicolon or comma it fails. Can anyone help? below is m
y
> code (see ToAddress string). Thanks.
> David
> strUser = UtilClass.GetUserName(strUser)
> '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
> Const ToAddress As String = "m...@.myemail.com"
> Const FromAddress As String = "m...@.myemail.com"
> '(1) Create the MailMessage instance
> Dim mm As New System.Net.Mail.MailMessage(ToAddress,
> FromAddress)
> '(2) Assign the MailMessage's properties
> mm.Subject = "Fileroom unhandled exception occurred!"
> mm.Body = "User getting error is " & strUser & vbCrLf & _
> String.Format("An unhandled exception
> occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
> System.Environment.NewLine, ex.Message, ex.StackTrace)
> mm.IsBodyHtml = False
> '(3) Create the SmtpClient object
> Dim smtp As New System.Net.Mail.SmtpClient
> '(4) Send the MailMessage (will use the Web.config setting
s)
> smtp.Send(mm)
in smtp, you write out a header per address, not a comma seperated list. to
support this mailmessage has a To collection, which you add as many addresse
s
as you want:
var mm = new MailMessage(toAddress1,fromAddress);
mm.To.Add(new MailAddress(toAddress2));
-- bruce (sqlwork.com)
"David C" wrote:

> I would like to have an email go to 2 email addresses but when I try it by
> separating with semicolon or comma it fails. Can anyone help? below is m
y
> code (see ToAddress string). Thanks.
> David
> strUser = UtilClass.GetUserName(strUser)
> '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
> Const ToAddress As String = "me@.myemail.com"
> Const FromAddress As String = "me@.myemail.com"
> '(1) Create the MailMessage instance
> Dim mm As New System.Net.Mail.MailMessage(ToAddress,
> FromAddress)
> '(2) Assign the MailMessage's properties
> mm.Subject = "Fileroom unhandled exception occurred!"
> mm.Body = "User getting error is " & strUser & vbCrLf & _
> String.Format("An unhandled exception
> occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
> System.Environment.NewLine, ex.Message, ex.StackTrace)
> mm.IsBodyHtml = False
> '(3) Create the SmtpClient object
> Dim smtp As New System.Net.Mail.SmtpClient
> '(4) Send the MailMessage (will use the Web.config setting
s)
> smtp.Send(mm)
>
>
"David C" <dlchase@.lifetimeinc.com> wrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...

>I would like to have an email go to 2 email addresses but when I try it by
>separating with semicolon or comma it fails.
Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
Mark Rae
ASP.NET MVP
http://www.markrae.net
Perfect. Thanks everyone.
David
"Mark Rae [MVP]" <mark@.markNOSPAMrae.net> wrote in message
news:eHV89AJLIHA.3992@.TK2MSFTNGP03.phx.gbl...
> "David C" <dlchase@.lifetimeinc.com> wrote in message
> news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...
>
> Well it would do - it's a collection...
> http://www.systemnetmail.com/faq/3.2.3.aspx
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

System.Net.Mail to address

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.

David
strUser = UtilClass.GetUserName(strUser)

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@dotnet.itags.org.myemail.com"
Const FromAddress As String = "me@dotnet.itags.org.myemail.com"

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)

'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False

'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.

protected void btnSendUpload_Click(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03;Initial
Catalog=CCTS;Persist Security Info=True;User
ID=UserID;Password=Password";
using (SqlConnection connection = new
SqlConnection(constring))
{
connection.Open();

SqlCommand command = new SqlCommand(queryString,
connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string captured = Convert.ToString(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(Your From
Address);
MailAddress to = new MailAddress(captured);
MailMessage msg = new MailMessage(from, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.NewLine + Environment.NewLine;
Attachment attach = new Attachment("\\\\glsdbs03\\d
$\\File\\LaborFile.txt");
msg.Attachments.Add(attach);
mailSvr.Send(msg);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}

I hope this helps

On Nov 21, 4:00 pm, "David C" <dlch...@.lifetimeinc.comwrote:

Quote:

Originally Posted by

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
>
David
strUser = UtilClass.GetUserName(strUser)
>
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "m...@.myemail.com"
Const FromAddress As String = "m...@.myemail.com"
>
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
>
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
>
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
>
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)


in smtp, you write out a header per address, not a comma seperated list. to
support this mailmessage has a To collection, which you add as many addresses
as you want:

var mm = new MailMessage(toAddress1,fromAddress);
mm.To.Add(new MailAddress(toAddress2));

-- bruce (sqlwork.com)

"David C" wrote:

Quote:

Originally Posted by

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
>
David
strUser = UtilClass.GetUserName(strUser)
>
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@.myemail.com"
Const FromAddress As String = "me@.myemail.com"
>
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
>
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
>
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
>
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
>
>
>


"David C" <dlchase@.lifetimeinc.comwrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I would like to have an email go to 2 email addresses but when I try it by
>separating with semicolon or comma it fails.


Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Perfect. Thanks everyone.

David
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:eHV89AJLIHA.3992@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

"David C" <dlchase@.lifetimeinc.comwrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...
>

Quote:

Originally Posted by

>>I would like to have an email go to 2 email addresses but when I try it by
>>separating with semicolon or comma it fails.


>
Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net