mailmessage - problem handling returns in body
I am having a problem with the body of an email accepting returns. This code will launch the default mail application and populate fields automatically. If the body has returns in it, the body in the new mail screen (in outlook in my case) --- shows in one continuous line.
The EmailBody field is populated with the contents of a text box with multiline property set to true. The operator enters the body in the text box returning between paragraphs. When outlook new mail panel is displayed, the whole body is displayed with no returns.
Is there something I need to do to allow for the returns?
VB Code:
Public Sub setEmailOutgoing(ByVal EmailServer As String, ByVal EmailTo As String, ByVal EmailFrom As String, ByVal EmailSubject As String, ByVal EmailBody As String, ByVal SMTPPort As Integer)
Dim mm As New MailMessage
Dim smtp As SmtpMail
If Not (EmailServer = "") Then
smtp.SmtpServer = EmailServer
End If
mm.To = EmailTo
mm.From = EmailFrom
mm.Subject = EmailSubject
mm.Body = EmailBody
If Not (SMTPPort = 0) Then
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", SMTPPort)
End If
smtp.Send(mm)
End Sub
Re: mailmessage - problem handling returns in body
I have reproduced your code and tested it.
First of all, what does mm.Fields.Add do? I know that it adds an entry into the IDictionary, but the help topic for MailMessage.Fields is incomplete in both VS and on MSDN.
Secondly, does your code really open the default e-mail client? I would love to be able to reproduce that behaviour but when I use it your code simply sends the message off itself. I thought that that was all you could do with the System.Web.Mail classes.
Thirdly, if I use a body with new-line characters in it, the e-mail message reproduces those characters faithfully when I receive it again. Are you sure your body has new-lines and is not just wrapped in the text box?