Link to home
Start Free TrialLog in
Avatar of RTKHOT
RTKHOTFlag for India

asked on

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
Avatar of appari
appari
Flag of India image


what error are you getting?
Avatar of RTKHOT

ASKER

Visual Basic .Net, IE7, Run-time exception thrown : System.Web.HttpException - Could not access 'CDO.Message' object
ASKER CERTIFIED SOLUTION
Avatar of Sachintana Dissanayake
Sachintana Dissanayake
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vjc2003
vjc2003

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.
Avatar of RTKHOT

ASKER

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
Avatar of RTKHOT

ASKER

thank you very much.