Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Monday, March 26, 2012

System.Net.Mail

This summary is not available. Please click here to view the post.

System.Net.Mail

I need to send the email with an email address that is not in my domain, but it will not do that. Can this be done

Yes. But your server may not accept it. Tell us how you know "it will not do that."

Jeff


Hi,

The machine that is running your application and sending emails must be added to the list of the allowed hosts on the smtp server you are trying to use as a relay - of course if that smtp server has restricted access.

system.net.mail - email sending no longer working

Hi,

Previously on my web app I had a contact page that would send an email to me with all the filled in values from the user. The email would be sent with the FROM address the user put in, so when I received it I could reply back to them. I had this working for years, and now all of a sudden it errors out.

I get the following error. Please note I was using System.Net.Mail, but changed to a component to try and debug.

I'm wondering what would cause this error to happen suddenly? Perhaps a configuration change in IIS ? What would be a good work around to this ? Is it possible to maybe email from my own domain, but specify a different ReplyTo address?


Thanks,
mike123

Additional Help:452 4.2.2 Mailbox full
] Verify you can send email on behalf of'userFilledInName@dotnet.itags.org.hotmail.com' through the mail server 'domainName.com to'admin@dotnet.itags.org.domainName.com'. 'domainName.com' may not allow relaying for that specific address or domain, resulting with a 500 or larger error.Your server may also require a username and password for authentication, check with your mail server administrator. For additional information, enable logging by setting EmailMessage.Logging = true and if you have file write permission set a path for EmailMessage.LogPath, then check the log. If you are sending from an ASP.NET application and do not have file write access, wrap the EmailMessage.Send() in a Try..Catch() block and call Response.Write( EmailMessage.GetLog() ) from inside or after the Catch(). To ignore this error; set IgnoreRecipientErrors = true
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: aspNetEmail.SmtpProtocolException: [Additional Help:452 4.2.2 Mailbox full
] Verify you can send email on behalf of'userFilledInName@dotnet.itags.org.hotmail.com' through the mail server 'domainName.com to'admin@dotnet.itags.org.domainName.com'. 'domainName.com' may not allow relaying for that specific address or domain, resulting with a 500 or larger error.Your server may also require a username and password for authentication, check with your mail server administrator. For additional information, enable logging by setting EmailMessage.Logging = true and if you have file write permission set a path for EmailMessage.LogPath, then check the log. If you are sending from an ASP.NET application and do not have file write access, wrap the EmailMessage.Send() in a Try..Catch() block and call Response.Write( EmailMessage.GetLog() ) from inside or after the Catch(). To ignore this error; set IgnoreRecipientErrors = true

Source Error:


Line 200:
Line 201:
Line 202: msg.Send()
Line 203: msg = Nothing
Line 204:

Destination Full means exactly that. You're sending to an address where the mailbox will accept no more messages. You can't fix this, the problem is the recipient needs to read their mail and empty their mailbox.

Jeff


Hi Jeff,

Thanks for the lightning quick reply, but sorry I forgot to include this part. I have emptied the mail box, it is definately not full. Also to make sure it wasnt a server side mail problem I also tried sending to other email addresses that also were verified to not be full.

I was thinking it might have something to do with the relaying ? I can paste mail logs if that might help ?

Thanks again,
Mike123


anybody have any other thoughts on this ?

much appreciated

mike123

System.Net.Mail Address Book Access

I would like to allow our users a chance to select a MailMessage.To
destination if they want to before the email is sent. Is there a way to popu
p
the address book from OutLook? At this point, I'm assuming I'll need to use
automation to add this function.
Thanks, Stew"Stew" <Stew@.discussions.microsoft.com> wrote in message
news:682A09C4-6DE6-46AD-A04C-932011F73219@.microsoft.com...

>I would like to allow our users a chance to select a MailMessage.To
> destination if they want to before the email is sent. Is there a way to
> popup
> the address book from OutLook? At this point, I'm assuming I'll need to
> use
> automation to add this function.
Slightly curious...
Assuming this is a corporate intranet site, chances are addresses would
normally be stored in your mail server (e.g. the GAL in Exchange Server), so
you fetch them from there...
Obviously, you wouldn't even contemplate doing something like this on a
public website because of the security implications, and you'd have no way
of knowing if Outlook was installed anyway...
Can you describe your environment a bit more...?
http://www.markrae.net
yes, sorry it is an intranet site.
"Stew" <Stew@.discussions.microsoft.com> wrote in message
news:D4ED302E-5818-4F6A-8FA9-2D63883D3010@.microsoft.com...

> yes, sorry it is an intranet site.
OK, so presumably you have a network mail server to which everybody's local
Outlook connects and which contains the global set of email addresses...?
http://www.markrae.net

System.Net.Mail Address Book Access

I would like to allow our users a chance to select a MailMessage.To
destination if they want to before the email is sent. Is there a way to popup
the address book from OutLook? At this point, I'm assuming I'll need to use
automation to add this function.

Thanks, Stew"Stew" <Stew@.discussions.microsoft.comwrote in message
news:682A09C4-6DE6-46AD-A04C-932011F73219@.microsoft.com...

Quote:

Originally Posted by

>I would like to allow our users a chance to select a MailMessage.To
destination if they want to before the email is sent. Is there a way to
popup
the address book from OutLook? At this point, I'm assuming I'll need to
use
automation to add this function.


Slightly curious...

Assuming this is a corporate intranet site, chances are addresses would
normally be stored in your mail server (e.g. the GAL in Exchange Server), so
you fetch them from there...

Obviously, you wouldn't even contemplate doing something like this on a
public website because of the security implications, and you'd have no way
of knowing if Outlook was installed anyway...

Can you describe your environment a bit more...?

--
http://www.markrae.net
yes, sorry it is an intranet site.
"Stew" <Stew@.discussions.microsoft.comwrote in message
news:D4ED302E-5818-4F6A-8FA9-2D63883D3010@.microsoft.com...

Quote:

Originally Posted by

yes, sorry it is an intranet site.


OK, so presumably you have a network mail server to which everybody's local
Outlook connects and which contains the global set of email addresses...?

--
http://www.markrae.net

System.Net.Mail & sending emails with line breaks

Hi,

When a client sends an email via a web form (text entered in a asp:TextBox server control), the email received has no line breaks, and it is displayed in one line. This has bad impact on email readability... How can one overcome this probelm?

Thank you,

Alon

If you are sending mail text in simple text format then you have to use System.Environment.NewLine to move rest text in next line.

SmtpMail.SmtpServer = "1.0.0.127";
MailMessage mm = new MailMessage();
mm.From = "bill@.microsoft.com";
mm.To = "job@.apple.com";
mm.Subject = "";
mm.Body = "line 1" + System.Environment.NewLine + "line 2";


Hi,

Thank you for your reply.

I forgot to metion that the mail is sent in HTML format:

mailMessage.IsBodyHtml =true;

Am I supposed to parse the user's message (the text in the TextBox control), chck for CRLF (or is it \n) and replace it with System.Environment.NewLine? Isn't there some standard way to send the email, as i is in the text box (multiline text box. It looks like a text area)?

Thank you,

Alon


Here is the modified code for HTML formated body

mm.Body = "line 1" + "<br>" + "line 2";

Rest of the code will remain same.


But how can I know where line1 ends and line2 starts? All I have is a string I get form TextBox.Text. From this string I cannot deduce where did the user hit return - it's a "flat" string.

A word about he context of this: this web form is a "Contact Us" page. The TextBox is a multiline text box, which serves as a free text input field.

Thank you,

Alon


As what Firoz said, you have to use the "<br />"

You will use the following code to replace each line in your textbox to break

Replace(textbox1.text, vbCrLf,"<br />")

HTH
Regards


Oooops, now I understand. It works. I thank the both of you.

Alon

System.NET.Mail and Outlook

Is there any way that I can use the System.NET.Mail classes to send an
email so that the sent emails appear in the Sent Email folder in
Outlook for the email address of the person that I am sending the email
fromyou'd have to use the outlook object to do that
<anewell@.valassis.co.uk> wrote in message
news:1151492707.136477.166730@.x69g2000cwx.googlegroups.com...
> Is there any way that I can use the System.NET.Mail classes to send an
> email so that the sent emails appear in the Sent Email folder in
> Outlook for the email address of the person that I am sending the email
> from
>
It would also have to be done on the client, not on the server.
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
Big thicks are made up of lots of little thins.
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:e$5CuEsmGHA.3980@.TK2MSFTNGP02.phx.gbl...
> you'd have to use the outlook object to do that
> <anewell@.valassis.co.uk> wrote in message
> news:1151492707.136477.166730@.x69g2000cwx.googlegroups.com...
>

System.NET.Mail and Outlook

Is there any way that I can use the System.NET.Mail classes to send an
email so that the sent emails appear in the Sent Email folder in
Outlook for the email address of the person that I am sending the email
fromyou'd have to use the outlook object to do that

<anewell@.valassis.co.uk> wrote in message
news:1151492707.136477.166730@.x69g2000cwx.googlegr oups.com...
> Is there any way that I can use the System.NET.Mail classes to send an
> email so that the sent emails appear in the Sent Email folder in
> Outlook for the email address of the person that I am sending the email
> from
It would also have to be done on the client, not on the server.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.

"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:e$5CuEsmGHA.3980@.TK2MSFTNGP02.phx.gbl...
> you'd have to use the outlook object to do that
> <anewell@.valassis.co.uk> wrote in message
> news:1151492707.136477.166730@.x69g2000cwx.googlegr oups.com...
>> Is there any way that I can use the System.NET.Mail classes to send an
>> email so that the sent emails appear in the Sent Email folder in
>> Outlook for the email address of the person that I am sending the email
>> from
>>

System.Net.Mail class smtpdemo needs users address in message body from txt.emailAddress

I have this code behind from the new asp.net 2.0 System.Net.Mail class smtpdemo i am working with. It sends an HTML email to myself the from address and to the email address in txt.emailAddress as a CC. I am trying to get the txt.email address somewhere in the message body that it sends out. this code does not show the imputed contents of txt.emailaddress anywhere in the email so i canot reply to the sender. It declaires me as the sender and sends the person filing out the form an email. I need to declar the contents of txt.emailadress as a variable and call it in the message body. Ive tryed dozens of different ways but they all have errors. i hope someone can look at this code and show me how to get the users email address sent with the message.
/code/
Imports System.Net.Mail

PartialClass report_aspx

Inherits System.Web.UI.Page

ProtectedSub sendEmail_Click(ByVal senderAsObject,ByVal e _

As System.EventArgs)Handles sendEmail.Click

Dim sBodyAsString

Dim fileReaderBodyAsString

Dim fileReaderFormatAsString

Dim WebDirectoryAsString = Server.MapPath(".") &"\"

Dim fileNameAsString = WebDirectory

Dim htmlEmailFormatAsString = WebDirectory &"MailFormat.htm"

SelectCase Subject.Text

Case"Broken Link"

fileName = fileName &"BrokenLink.txt"

Case"Missing Picture"

fileName = fileName &"MissingPicture.txt"

Case"Typographical Error"

fileName = fileName &"TypoError.txt"

CaseElse

fileName = fileName &"other.txt"

EndSelect

fileReaderBody =My.Computer.FileSystem.ReadAllText(fileName)

fileReaderFormat =My.Computer.FileSystem.ReadAllText(htmlEmailFormat)

sBody = fileReaderFormat.Replace("BODYGOESHERE", _

messageBody.Text)

sBody = sBody.Replace("CONTENTGOESHERE", fileReaderBody)

sBody = sBody.Replace("SUBJECTGOESHERE", Subject.Text)

Dim toAddressAs MailAddress =New _

MailAddress(me@dotnet.itags.org.myemailaddress,"Webmaster")

Dim ccAddressAs MailAddress =New _

MailAddress(emailAddress.Text, emailName.Text)

Dim SenderAddressAs MailAddress =New _

MailAddress(emailAddress.Text)

Dim fromAddressAs MailAddress =New _

MailAddress(me@dotnet.itags.org.myemailaddress)

Dim eMailAs MailMessage =New _

MailMessage(fromAddress, fromAddress)

eMail.CC.Add(fromAddress)

eMail.Subject = Subject.Text

Dim htmlTypeAs System.Net.Mime.ContentType = _

New System.Net.Mime.ContentType("text/html")

Dim txtTypeAs System.Net.Mime.ContentType = _

New System.Net.Mime.ContentType("text/plain")

eMail.AlternateViews.Add( _

AlternateView.CreateAlternateViewFromString(sBody, htmlType))

eMail.AlternateViews.Add( _

AlternateView.CreateAlternateViewFromString(fileReaderBody & vbCrLf & messageBody.Text, htmlType))

Dim attchmentAs Attachment =New _

Attachment(WebDirectory &"goldbar.gif")

eMail.Attachments.Add(attchment)

Dim clientAs SmtpClient =New SmtpClient("myemailserver")

client.Send(eMail)

lblMessageSent.Text ="MESSAGE SENT"

emailAddress.Text =""

emailName.Text =""

messageBody.Text =""

EndSub

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

EndSub

EndClass
/end code/

I fixed my form by modifying the mailformat.htm page that I will place below and adding:

/codebehind file/
Body = sBody.Replace("NAMEGOESHERE", emailName.Text)

sBody = sBody.Replace("EMAILFROMGOESHERE", emailAddress.Text)
/end codebehind file/
/mailformat.html/

<html><body><h1>SUBJECTGOESHERE</h1><imgsrc="goldbar.gif"/><br/>BODYGOESHERE

<br/>

<imgsrc="goldbar.gif"/><br/>

NAMEGOESHERE<br/>

EMAILFROMGOESHERE<br/>

<br/>

<blockquote>CONTENTGOESHERE</blockquote></body></html>

System.Net.Mail force or set send time/delay

Hi

Is it possible to when creating and sending an email in .NET 2.0 to specify the time you want it sent. Just like in Outlook, you can say, deliver on "Date @dotnet.itags.org. Time".

Looked at VS IDE and no options are given.

Thanks
Anthony

No, scheduled emails requires an application that stays alive for the duration of the schedule, and the .NET framework can't be responsible for such tasks.

You will have to take care of the scheduling and sending yourself, e.g by storing the email in a database and have a running process (a Windows Service) that continually polls the database and checks if there's something to send.

system.net.mail email tagged as spam!

Hi - I have a small room booking application running, where people logon, and book a room. THey should then get an email confirmation, sent directly from my web app (vb.net - .net2), which uses the system.net.mail class. However, I'm getting more and more people reporting they have not received the confirmation, and most recently, someone advising SPAMASSASSIN reported my email as being spam!

I'm not sure how this happens - as it's a request from someone for a booking, and all I'm doing is replying to their supplied email address, through my web app.

Is there some way I can add an identifier, to 'legitimise' my email?

Before asking, no, I'm not a spammer - I've posted several queries here over the last few years, and am a genuine developer - with a new problem to try and overcome.

Thanks for any help/pointers,

Mark

Im not sure of any ways to legitimize your messages, maybe its because of keywords that you are using in your subject line or body that is causing it to be filtered as spam, or maybe it is the web address you are sending it from.

Usually a subject line is a dead give away of spam though and many programs search for keywords in the subject and body to try to Identify spam, im sure if you search around on google you can find a keyword list and try to improve the context of your messages.

If that doesnt work then i am sorry i cant be much more help.

good luck :)


I'd try to contact SPAMASSASSIN or other anti-spam companies with your problem. I know of 1 other companies, Postini (http://www.postini.com/) which does anti-spam filtering for corporate email systems.


Hi - thanks for the suggestions so far - I will follow up where possible.

In the meantime, I read this (from a link on SPAMASSASSINS website):

"If your message is in HTML,DO include all of the MIME message headers that identify it as HTML. (You'd think this would be obvious, but mailers from the NY Times to Air Canada send HTML messages missing the mime-version header.)" fromhttp://spam.abuse.net/marketerhelp/bulk-howto.shtml

I'm not advocating it, as I'm not certain if it's trying to help, or tell you how to spam - but how from the system.net.mail webspace, how do you include MIME headers, and what should they contain?

Thanks, Mark


I've really done something on anti-spam research before.. Based on my understanding, i don't think it has anything to do with the "MIMI" message(note my suggestion could be WRONG).

i think in your case, the reason probably is that there are some not welcomed words exist in your mail thus cause your email recognized as a spam. So, maybe youshould first check the content of your mail(send the same email using another account like..yahoo..gmail..etc, and see if it's still recognized as spam)

Hope my suggestion helps


Hi BC - thanks.

Do you mean send to a GMAIL/Yahoo email address, or send from one - are there any programs which you can send some html to, to hilight the problem areas?

Thanks, Mark


and most recently, someone advising SPAMASSASSIN reported my email as being spam!

If you can still contact this "someone", send him/her the same confirmation email FROM a yahoo/hotmial/gmail account and see if it's still recognized as a spam. thanks

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

System.Net.Mail.SmtpClient

Hi all,

We are using the Asp.Net SMTP Client to send email via our Exchange 2003 SP2
Server. When trying to send email to a local recipient I am getting the
following error:-

Server: 172.19.2.21. Message: Mailbox unavailable. The server response was:
5.7.1 Requested action not taken: message refused

What is causing this? The asp.net machine is on the same LAN as the Exchange
Server. I checked the Exchange Server and all local IPs are in the "allow"
list.

TIA!How do you have the Recipient MailAddress setup? Are you using
name@.domain.local or name@.domain.com
Sounds like an issue with formatting the address correctly, and now
with SmtpClient

param@.community.nospam wrote:

Quote:

Originally Posted by

Hi all,
>
We are using the Asp.Net SMTP Client to send email via our Exchange 2003 SP2
Server. When trying to send email to a local recipient I am getting the
following error:-
>
Server: 172.19.2.21. Message: Mailbox unavailable. The server response was:
5.7.1 Requested action not taken: message refused
>
>
What is causing this? The asp.net machine is on the same LAN as the Exchange
Server. I checked the Exchange Server and all local IPs are in the "allow"
list.
>
TIA!


For the recipient mailaddress I am using name@.domain.com
If I change the SMTPServer on the SMTPClient to another smtp server,
everything works fine.

What could be causing this?

"Sean Chambers" <dkode8@.gmail.comwrote in message
news:1158344339.960590.194450@.h48g2000cwc.googlegr oups.com...

Quote:

Originally Posted by

How do you have the Recipient MailAddress setup? Are you using
name@.domain.local or name@.domain.com
>
Sounds like an issue with formatting the address correctly, and now
with SmtpClient
>
param@.community.nospam wrote:

Quote:

Originally Posted by

>Hi all,
>>
>We are using the Asp.Net SMTP Client to send email via our Exchange 2003
>SP2
>Server. When trying to send email to a local recipient I am getting the
>following error:-
>>
>Server: 172.19.2.21. Message: Mailbox unavailable. The server response
>was:
>5.7.1 Requested action not taken: message refused
>>
>>
>What is causing this? The asp.net machine is on the same LAN as the
>Exchange
>Server. I checked the Exchange Server and all local IPs are in the
>"allow"
>list.
>>
>TIA!


>


I have complete 1.1 and 2.0 examples here:
http://sholliday.spaces.live.com/
2/8/2006 entry.

You need to try the different authentication modes.

Also. check C:\Inetpub\mailroot and see if they're jammed up there.

<param@.community.nospamwrote in message
news:%23gNx4lQ2GHA.1548@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

For the recipient mailaddress I am using name@.domain.com
>
If I change the SMTPServer on the SMTPClient to another smtp server,
everything works fine.
>
What could be causing this?
>
"Sean Chambers" <dkode8@.gmail.comwrote in message
news:1158344339.960590.194450@.h48g2000cwc.googlegr oups.com...

Quote:

Originally Posted by

How do you have the Recipient MailAddress setup? Are you using
name@.domain.local or name@.domain.com
Sounds like an issue with formatting the address correctly, and now
with SmtpClient

param@.community.nospam wrote:

Quote:

Originally Posted by

Hi all,
>
We are using the Asp.Net SMTP Client to send email via our Exchange


2003

Quote:

Originally Posted by

Quote:

Originally Posted by

Quote:

Originally Posted by

SP2
Server. When trying to send email to a local recipient I am getting the
following error:-
>
Server: 172.19.2.21. Message: Mailbox unavailable. The server response
was:
5.7.1 Requested action not taken: message refused
>
>
What is causing this? The asp.net machine is on the same LAN as the
Exchange
Server. I checked the Exchange Server and all local IPs are in the
"allow"
list.
>
TIA!



>
>


Hello Param,

As for the send mail code, are you using the "Network" as the SmtpClient's
"SmtpDeliveryMethod" and have you tried supply a credential or use the
default credential. Also, when using Exchange server in a domain
environment, you should make sure you have permission to send mail as the
"From" address since exchange server will validate this at server-side.

In addition, as you mentioned it works when using another SMTP server, is
that SMTP server a normal SMTP relay server which also transfer message to
another exchange server? If possible you can also create a local
smtpserver through IIS which act as a relay server to the Exchange server
and send mail through this local SMTP server to see whether it works.

So far based on my experience, it is likely a server environment specific
issue. Here is a simple code snippet which works for sending mail to local
domain user through local network exchange server:

==========================
private void btnSend_Click(object sender, EventArgs e)
{
MailMessage msg = new
MailMessage("steven@.microsoft.com","steven@.microsoft.com");
msg.Subject = "Smtp Client Test Message";
msg.IsBodyHtml = true;
msg.Body = "<font size='30'>Hello World</font>";

SmtpClient sc = new SmtpClient("smtphost");

sc.DeliveryMethod = SmtpDeliveryMethod.Network;

sc.UseDefaultCredentials = true;

sc.Send(msg);

}
===========================

Please feel free to post here if you have any other finding or any other
questions on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...rt/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Saturday, March 24, 2012

System.Net.Mail.SmtpClient.Send() Error: An invalid character was found in the mail header

hi all!

please help!

I wanted to make an automatic email when I create user by CreateUserWizard. So I configured SMTP, then in properties of the wizard indicated textfile for message and wrote simple subject "registration"

but I have an exception (like in subj).

I even tried to set the subject in event handler for "emailsending" event. Same exception.

What is wrong? How could I fix it?

Here us some info from stack:

[FormatException:An invalid character was found in the mail header.] System.Net.BufferBuilder.Append(String value, Int32 offset, Int32 count) +915954 System.Net.Mail.EHelloCommand.PrepareCommand(SmtpConnection conn, String domain) +106 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +835 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316 System.Net.Mail.SmtpClient.GetConnection() +42 System.Net.Mail.SmtpClient.Send(MailMessage message) +1485

[SmtpException: Email send failure.] System.Net.Mail.SmtpClient.Send(MailMessage message) +2074 System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341 System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571 System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105 System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453 System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149 System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +171 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Hi there, can i just ask why you choose me? as for your problem, it looks like there is an invalid character in the mail header, so either there is nothing in it or something there shouldnt be, try taking a few steps back, if your attaching a text file just simply put a few words coded in, and if your header is dynamic try making it hard coded


You were online. Sorry.

It is more simple. There is simpliest string, like "123". Same error


hey no worries, well try a string like abc, also make sure no fields are not left blank. What usually helps me is take a 10 min break, clear you head have a coffee and come back look through your code as if you have never seen it before. something may catch. Im not the worlds best .neter but i usually find if there is a problem its often by taking things back to basic it helps


If your still not having any success you could try the code below and see if it makes any difference.

Regards

Martijn

Sub mailout()Dim mailAsNew Net.Mail.MailMessage()

'set the addresses

mail.To.Add("recipient@.whereever.com")

mail.From =New Net.Mail.MailAddress("sender@.wherever.com"))

'set the content

mail.Subject ="Email Subject line"

mail.Body ="The main body of the email message"

'send the message

Dim smtpAsNew Net.Mail.SmtpClient("smtp.whereever.com")

'to authenticate we set the username and password properites on the SmtpClient

smtp.Credentials =New Net.NetworkCredential("smtp-accountname e.g. sender@.wherever.com","smtp-account-password")

Try

smtp.Send(mail)

response.write("Email sent successfully")

Catch ExAs Exception

response.write("Email send failed error code is... " & Ex.Message)

EndTry

EndSub


no success, same error


I cant come up with any conclusions from your stack trace.

The code I gave you I copied out of an application I wrote there was something I had missed and should have cleaned up in the following line

mail.From =New Net.Mail.MailAddress(Session(sender@.wherever.com))

It should be this (no reference to any session variable)

mail.From =New Net.Mail.MailAddress(sender@.wherever.com)

The only other question is does your recipient or sender email address have any unusual charactors or attempt to have a space in it? Any thing like that could cause a problem. Try the same code with different email addresses and different content.

Sorry no other suggestions

Martijn


May be this piece of code will help:

<system.net>
<mailSettings>
<smtp from="evdokp@.pochta.ru">
<network host="mail.pochta.ru" password="[мой пароль]" userName="evdokp@.pochta.ru" />
</smtp>
</mailSettings>
</system.net>

this is how ASP.NET build-it configuration tool edits web.config

Well, my additional question is: where does the tool sets port value?


ok, my sugesstion is to take remove the brackets from the password and to use a password with standard English character set without and spaces.

Be sure to update the password on the mail server too.

Good luck

<system.net>
<mailSettings>
<smtp from="evdokp@.pochta.ru">
<network host="mail.pochta.ru" password="myPassword" userName="evdokp@.pochta.ru" />
</smtp>
</mailSettings>
</system.net>


it is not that easy.

these brackets are there just because I hide my password. It was like you say "myPassword"

Do you know where port is defined in web.config?

System.Net.Mail.SmtpException

My webserver does not have smtp on it but I'm still able to relay email to my email server with user name and password, my first question is that the dotnet is using an API that's built into server to relay?

Also email stopped working a day ago with error messageSyntax error, command unrecognized. The server response was: 5.1.0 Dropping connection due to an error on this server . Could this error be caused by the internal process dotnet uses to relay not working?

The 5.1.0 error is usually on the remote SMTP server and the error is propogated back to you. Does the server you relay to allow relays?

You're not relaying. System.Net.Mail simply sends the message to the defined SMTP server. Your error is a SMTP error, check the logs on the SMTP server to see what is happening, if you can. A 5.1.0 is a Sender Denied error, which most likely means you now need to use authentication. Checkwww.systemnetmail.com for help and samples.

Jeff


Still not getting this working getting, any help would be appreciated.

System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it

Line 88: try
Line 89: {
Line 90: client.Send(message);
Line 91: Response.Redirect("RequestAccepted.aspx");
Line 92: }
Source File:d:\Inetpub\KPClient\ContactUS.aspx.cs Line:90

Stack Trace:

[SocketException (0x274d): No connection could be made because the target machine actively refused it] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +1001874 System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431[WebException: Unable to connect to the remote server] System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +1447464 System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +190 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +318 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +227 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316 System.Net.Mail.SmtpClient.GetConnection() +42 System.Net.Mail.SmtpClient.Send(MailMessage message) +1485


This turned out to be a bad router change that was not documented.

Tuesday, March 13, 2012

'System.ServiceModel/ServiceHostingEnvironment' configuration section cannot be c

On Jun 5, 11:22 pm, "Sachin" <Sachi...@dotnet.itags.org.Email.com> wrote:
> On both server its .NET 2.0
>
Did you installed the .NET 3.0 on the Server2?No.
This is what I get at the bottom of the error page.
Version Information: Microsoft .NET Framework Version: 2.0.50727.42; ASP.NET
Version:2.0.50727.210
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1181079744.934238.48060@.q66g2000hsg.googlegroups.com...
> On Jun 5, 11:22 pm, "Sachin" <Sachi...@.Email.com> wrote:
> Did you installed the .NET 3.0 on the Server2?
>
re:
!> This is what I get at the bottom of the error page.
!> Version Information: Microsoft .NET Framework Version: 2.0.50727.42;
!> ASP.NET Version:2.0.50727.210
That looks like a W2K3 R2 install on Server2. Is it ?
Is it the same version which is installed on Server1 ?
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Sachin" <SachinGp@.Email.com> wrote in message news:uX0uSz7pHHA.3892@.TK2MSFTNGP05.phx.gbl..
.
> No.

> This is what I get at the bottom of the error page.
> Version Information: Microsoft .NET Framework Version: 2.0.50727.42; ASP.NET Versi
on:2.0.50727.210
> "Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
> news:1181079744.934238.48060@.q66g2000hsg.googlegroups.com...

'System.ServiceModel/ServiceHostingEnvironment' configuration section cannot be c

On Jun 5, 10:10 pm, "Sachin" <Sachi...@dotnet.itags.org.Email.com> wrote:
> Hi All,
> I deployed an ASP.NET Web Service on Server1 and it worked fine.
> However when I deployed the same Web Service on Server2 I am getting the
> following error,
> The 'System.ServiceModel/ServiceHostingEnvironment' configuration section
> cannot be created.
> The Machin.config file is missing information.
> Verify that this configuration section is properly registered and that you
> have correctly splled the section name.
> For Windoes Communication Foundation sections, run ServiceModelReg.exe -i
to
> fix this error.
> ...................
> I never saw this error. What could be wrong?
> Any pointer?
> Thanks in advance
> Sachin
Verify the version of ASP.NET.
aspnet_regiis -ls
aspnet_regiis -i
etc...On both server its .NET 2.0
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1181074886.601979.301780@.n4g2000hsb.googlegroups.com...
> On Jun 5, 10:10 pm, "Sachin" <Sachi...@.Email.com> wrote:
> Verify the version of ASP.NET.
> aspnet_regiis -ls
> aspnet_regiis -i
> etc...
>