[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1033
  • Last Modified:

ASP.Net Sending Mail Via EWS Removes line breaks in body

Hi

I have a textbox on a page which I use as the body of an e-mail I’m trying to send out.  The e-mail works fine, but the body is 1 long sting whereas before it was on several lines e.g.

Line1
Line2
Line3
On e-mail looks like
Line1Line2Line3

My code is below

Any one any ideas??

Thanks  

Brasso

'Text Box Im suning as body'
    <asp:TextBox ID="TXTMB" runat="server" Height="175px" TextMode="MultiLine" 
        Width="600px"></asp:TextBox>

'VB To Send Mail'

        Try

            Dim service As New ExchangeService(ExchangeVersion.Exchange2007_SP1)
            service.Credentials = New WebCredentials("####", "####", "####")
            service.AutodiscoverUrl("######")

            Dim message As New EmailMessage(service)
            message.Subject = txtsubject.Text
            message.Body = TXTMB.Text
            message.ToRecipients.Add(txtto.Text)
            message.CcRecipients.Add(txtcc.Text)
            message.SendAndSaveCopy()


            ' ' Write confirmation message to console window.
            txtSavRes.Text = ("Message sent!")

        Catch ex As Exception
            txtSavRes.Text = ("Error: " & ex.Message)

        End Try

Open in new window

0
brasso_42
Asked:
brasso_42
1 Solution
 
Alfred A.Commented:
Hi,

Is your mail message body set as html?  If it is you have to replace all new lines with <br />

message.Body = TXTMB.Text.Replace(Environment.NewLine,"<br />")
0
 
brasso_42Author Commented:
great thanks
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now