473,498 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting is lost while sending mail in .Net 2.0

8 New Member
Hi Everybody,

I am sending mail using the new class in .Net 2.0.
Here while sending internal mails it is giving me problem.
Carriage return, Line feed and Spaces are lost while sending mails.
I am using msg.BodyEncoding = System.Text.UTF8Encoding.UTF8 to encode the body.
But same code and same mail is going fine , when sent to external mails (Like gmail, yahoo, etc.)
Please can anyone help me in solving my problem.
I even tried replacing the carriage return and lifeed like this,
If InStr(mStrBody, CChar(Microsoft.VisualBasic.Chr(13)) + CChar(Microsoft.VisualBasic.Chr(10)), CompareMethod.Binary) Then
mStrBody.Replace(CChar(Microsoft.VisualBasic.Chr(1 3)) + CChar(Microsoft.VisualBasic.Chr(10)), vbCrLf)
End If
But too its not working.
Thank you all in advance.
Deepak
May 31 '07 #1
3 2360
Plater
7,872 Recognized Expert Expert
You can use '\n' and '\r' instead of all that messy CHAR(13) business.
The common windows scheme is to have a \r\n.
If your messages are being sent as html (You didn't say) then you will need a <br/> wherever you want a new line to occur. Also, if it's html, a bunch of spaces will be condensed into a single space. You will need to use like &nbsp; to get extra spaces.

But I would first ensure that your emails are being sent as plain text.
May 31 '07 #2
dskinibbyb
8 New Member
You can use '\n' and '\r' instead of all that messy CHAR(13) business.
The common windows scheme is to have a \r\n.
If your messages are being sent as html (You didn't say) then you will need a <br/> wherever you want a new line to occur. Also, if it's html, a bunch of spaces will be condensed into a single space. You will need to use like &nbsp; to get extra spaces.

But I would first ensure that your emails are being sent as plain text.
Hi Plater,
I am Sending the mail as html only if the option IsHtml is ticked in my application. Can you plz tell me how to use (Or set ) the message.Body.Format to "Plain/Text". Actually the code is as follows, here i am replacing each "\r\n" i.e. "vbCrLf" with 2 vbCrLf's, then i was getting the mail in correct format.
the code is as follows..
Public Sub Send(ByVal strServerName As String, ByVal strUserName As String, ByVal strPassword As String)
Dim msg As System.Net.Mail.MailMessage
Dim objSMTP As New System.Net.Mail.SmtpClient(strServerName)
Dim oAttachments As Attachment
Dim arrTmp As Array
Try
If mIntId <> 0 Then
If mDtNextRetry.TimeOfDay <= System.DateTime.Now.TimeOfDay Then
Try
msg = New System.Net.Mail.MailMessage(mStrFrom, CStr(mStrTo), CStr(mStrSub), mStrBody)
If mStrCC <> "" Then
arrTmp = Split(mStrCC, ";")
For Each strCC As String In arrTmp
If strCC <> "" Then
msg.CC.Add(New MailAddress(strCC))
End If
Next
End If
If mStrBcc <> "" Then
arrTmp = Split(mStrBcc, ";")
For Each strBcc As String In arrTmp
msg.Bcc.Add(New MailAddress(strBcc))
Next
End If
msg.IsBodyHtml = mBlnIsHtml
msg.BodyEncoding = System.Text.UTF8Encoding.UTF8
msg.DeliveryNotificationOptions = Net.Mail.DeliveryNotificationOptions.OnFailure
For Each strAttachment As String In mColAttachment
oAttachments = New Attachment(strAttachment)
msg.Attachments.Add(oAttachments)
Next
objSMTP.Credentials = New System.Net.NetworkCredential(strUserName, strPassword)
objSMTP.DeliveryMethod = SmtpDeliveryMethod.Network
msg.Body = msg.Body.Replace(vbCrLf, vbCrLf + vbCrLf)
objSMTP.Send(msg)
mIntStatus = MailStatus.Sent
mDtSentOn = System.DateTime.Now
Catch ex As Exception
mIntAttempt = mIntAttempt + 1
If mIntAttempt = 3 Then
mIntStatus = MailStatus.UnSendable
Else
mIntStatus = MailStatus.ErrorInMail
End If
mDtNextRetry = System.DateTime.Now.Date.Add(System.DateTime.Now.T imeOfDay).AddHours(2)
mDtSentOn = CDate("1-1-1900")
End Try
UpdateMail()
End If
End If

Catch ex As Exception
Throw ex
End Try
End Sub
Can u suggest me is anything is wrong inthis code?
Thanks
Deepak
Jun 1 '07 #3
Plater
7,872 Recognized Expert Expert
For HTML, "\r\n" (vbCRLF) is not an html line termination string. I would make a check to an html quickguide to do some formating.

For Plain Text, how it looks in a textbox is how it should look when it's sent, without any changes required.
Jun 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4353
by: Jonathan | last post by:
Hi, I have to use the nl2br function in the asp file, luckly I got this code from a site. What I need done is to display textbox content the way it was typed/pasted i.e. with paragraph breaks and...
2
1924
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
2
9203
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
7
2743
by: Amir Michail | last post by:
Hi, I would like to add a submission bookmarklet to my app that takes the current selection and pastes it into the app's rich text editor while preserving formatting. It should work in at least...
1
1257
by: SAL | last post by:
Hello, I am sending an e-mail message from my ASP.NET 2.0 application. The body of the message is coming from a database and formatting has already been applied to the text. My problem is that if...
9
3431
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
4
2378
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I use: Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text) Dim emailClient As New SmtpClient(txtSMTPServer.Text) emailClient.Send(message) And its...
3
5001
by: stevenrec | last post by:
Hi, maybe someone else has the knowledge. I have a working function sending an email through LN from Access, but am having a formating problem. Need to add a "sendto:x...@xyz.com?subject= Question...
1
2074
by: =?Utf-8?B?UGFzcXVhbGU=?= | last post by:
I want to send an email with smtpclient. I have created a MailMessage with body obtained as concatenation between a fixed string, that finishes with a space, and a string variable. The code is as...
0
6998
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
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.