• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

unable to send email if i add <br> tag

I am trying to send an email using asp.net 1.1
My web form has a textarea field, which allows typing address using the 'enter' key for line feed.
In the code behind, i am replacing chr(13) with "<BR>". The code is as below:
pstrEmailBody = pstrEmailBody & "<td>" & Replace(txaAddress.Value, Chr(13), "<br>") & "</td>"

when i see the contents of pstrEmailBody in the immediate window, i see the breaks correctly. i also copied the output into an HTML file, and it is perfect. However, when sending out the email, i get the above error. If i remove the replace part, then the email goes correctly, but the address comes on a single line in the email.

I have also attached the email function. see below:

Public Sub SendMail(ByVal EmailBody As String, ByVal FirstName As String, ByVal LastName As String)
        Dim objMail As Mail.MailMessage
        Dim objSMTPMail As SmtpMail
        Dim pstrError

        Try
            objMail = New Mail.MailMessage
            objMail.From = "riaz@sanginfo.com"
            objMail.To = "riaz@sanginfo.com"
            objMail.BodyFormat = MailFormat.Html
            objMail.Body = EmailBody
            objMail.Subject = "New Tutor Application - " & FirstName & " " & LastName
            objSMTPMail.SmtpServer = ConfigurationSettings.AppSettings.Item("SMTPMailServer")
            objSMTPMail.Send(objMail)
        Catch ex As Exception
            pstrError = ex.ToString()
        Finally
            If Not objSMTPMail Is Nothing Then objSMTPMail = Nothing
            If Not objMail Is Nothing Then objMail = Nothing
        End Try
    End Sub
0
RTKHOT
Asked:
RTKHOT
1 Solution
 
appariCommented:

what error are you getting?
0
 
RTKHOTAuthor Commented:
Visual Basic .Net, IE7, Run-time exception thrown : System.Web.HttpException - Could not access 'CDO.Message' object
0
 
Sachintana DissanayakeSenior Web DeveloperCommented:
Replace this line with Environment.NewLine,



pstrEmailBody = pstrEmailBody & "<td>" & Replace(txaAddress.Value, Environment.NewLine , "<br>") & "</td>"

Open in new window

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

 
vjc2003Commented:
Looks like it is not a problem with your mail body
The "Could not access 'CDO.Message' object" error could be because the SMTP Server is not
available or might not be configured properly.
You can try with an empty mail body to test this.
0
 
RTKHOTAuthor Commented:
it work perfectly and the email gets delivered properly if i do not have that replace code. i have not yet tried the environment.newline. i will let you know how it goes. thanks everyone
0
 
RTKHOTAuthor Commented:
thank you very much.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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