Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Monday, March 26, 2012

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.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.