Link to home
Start Free TrialLog in
Avatar of FullWilliams
FullWilliams

asked on

Random "!" in MailMessage

Hi there,

I have a registration form that mails the user their submitted information.  For some reason the users are recieving radom "!" in their text.

Like there Title will be

Director or !Communications

Any thoughts as to why this might be happening.

Dim objMail As New System.Web.Mail.MailMessage()        
        objMail.From = "icdr@cessi.net"
        Dim Stremail as string
        Dim varField as string
        Dim strSelect As String                
            Dim cmdSelect As SqlCommand                
            Dim dtrReg as SqlDataReader
        Dim strBody as String      
            Dim conPubs As New SqlConnection(ConfigurationSettings.appSettings("sqlconnectionString"))
        conPubs.Open()

            stremail = email.Text
            objMail.To = stremail
        objMail.Subject = "Employer Perspectives on Workers with Disabilities"
        objMail.BodyFormat = MailFormat.Html        
        strBody = strBody

strBody = strBody &  "</p>"
            
        objMail.Body =  strBody        
        ' ** SMTP PORT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25") 'Put port number here
        ' ** CDO PORT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2")
          ' ** TIMEOUT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", "60")

        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "x")
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "x")  

        System.Web.Mail.SmtpMail.SmtpServer = "xx"
        System.Web.Mail.SmtpMail.Send(objMail)
              
        objMail = Nothing
Avatar of lojk
lojk
Flag of United Kingdom of Great Britain and Northern Ireland image

if you set objMail.BodyFormat = MailFormat.Text, do you have the same problem?

How about using one of the Text.Encoding methods to encode the entered text to UTF8?

also
   Dim strBody as String      
   strBody = strBody

?

surely you mean

 
  objMail.Body ="<p> & UserEnteredBody & "</p>")

Although i would doubt that would make a difference but certainly makes the code more readable/logical
Avatar of FullWilliams
FullWilliams

ASKER

MailFormat.Text isn't going to work because I need hyperlinks in the strBody.  I left out the strBody text because it's rather lengthly

this is an example of one of my lines that is getting the "!":

strBody = strBody & "Title: " & title.Text & "<br>"
I asked if you had the same problem if set to text.. If so it will help to eliminate many possibilities.

can we see some of that strbody declaration, i think its probably very relevant.

Im certain is an invalid character that is being slipped in somewhere... But we need to see all of the code (that is 'public-able')

Cheers
Here you go..thanks.

Sub EmailCessi
        Dim objMail As New System.Web.Mail.MailMessage()        
        objMail.From = "icdr@cessi.net"
        Dim Stremail as string
        Dim varField as string
        Dim strSelect As String                
            Dim cmdSelect As SqlCommand                
            Dim dtrReg as SqlDataReader
        Dim strBody as String      
            Dim conPubs As New SqlConnection(ConfigurationSettings.appSettings("sqlconnectionString"))
        conPubs.Open()

            stremail = email.Text
            objMail.To = stremail
        objMail.Subject = "Employer Perspectives on Workers with Disabilities"
        objMail.BodyFormat = MailFormat.Html      
        strBody = "Thank you for registering for the ICDR conference: Employer Perspectives on Workers with Disabilities: <br> " & _
        "A National Summit to Develop a Research Agenda on September 19-20, 2006 at the Doubletree Hotel Crystal City in Arlington, Virginia. <br> " & _
        "As a courtesy, we have included your registration form below.  If you see any inaccuracies on your form or would like additional information, <br> " & _
        "please contact Reggie Clyburn, CESSI/New Editions Conference Planner, e-mail: <a href=mailto:rclyburn@neweditions.net>rclyburn@neweditions.net</a> or phone: 703-356-8035 x104. <br> " & _
        "Logistical information regarding conference location, driving directions and meeting materials is available at <a href=http://www.icdr.us/employment>www.icdr.us/employment</a>.      <br>" & _
        "(If the link doesn't open in your browser, please copy and paste it into your browser)<br>" & _
        "<p>" & _
        "<strong>Registration Form:</strong><br>" & _
        "Name: " & fname.Text & " " & lname.Text & "<br>"

        'Role
        strSelect = "Select * From tblRole WHERE (id=@RoleID)"                
        cmdSelect = New SqlCommand(strSelect, conPubs)
        cmdSelect.Parameters.Add( "@RoleID", ddlrole.SelectedValue )
        dtrReg = cmdSelect.ExecuteReader()
       
            While dtrReg.Read
            varField = dtrReg.Item("role")            
            strBody = strBody & "Role: " & varField & "<br>"
        End While
        dtrReg.Close                                         
       
        'Attendance
        Select Case attendance.SelectedValue
            Case 1
                strBody = strBody & "Attendance: Both Days<br>"
            Case 2
                strBody = strBody & "Attendance: Only First Day<br>"
            Case 3
                strBody = strBody & "Attendance: Only Second Day<br>"
        End Select
       
       
        strBody = strBody & "Degree: " & degree.Text & "<br>"
        strBody = strBody & "Title: " & title.Text & "<br>"
        strBody = strBody & "Org: " & org.Text & "<br>"
       
        If request.querystring("formtype")= 1 then 'international
            strBody = strBody & "Address: " & int_add.Text & "<br>"
            strBody = strBody & "Phone: " & int_phone.Text & "<br>"
            strBody = strBody & "Phone Ext: " & int_phoneext.Text & "<br>"
            strBody = strBody & "Fax: " & int_fax.Text & "<br>"
            strBody = strBody & "TTY: " & int_tty.Text & "<br>"
        Else ' US
            strBody = strBody & "Address: " & add1.Text & "<br>"
            strBody = strBody & "Address2: " & add2.Text & "<br>"
            strBody = strBody & "City: " & city.Text & "<br>"
            'State
            strSelect = "Select * From tblStates WHERE (id=@dropState)"                
            cmdSelect = New SqlCommand(strSelect, conPubs)
            cmdSelect.Parameters.Add( "@dropState", dropState.SelectedValue )
            dtrReg = cmdSelect.ExecuteReader()
           
                While dtrReg.Read
                varField = dtrReg.Item("State_Acronym")            
                strBody = strBody & "State: " & varField & "<br>"
            End While
            dtrReg.Close            
            strBody = strBody & "Zip: " & zip.Text & "<br>"
            strBody = strBody & "Phone: " & phone.Text & "<br>"
            strBody = strBody & "Phone Ext: " & phoneext.Text & "<br>"
            strBody = strBody & "Fax: " & fax.Text & "<br>"
            strBody = strBody & "TTY:" & tty.Text & "<br>"
        End if
       
        If ddlAccommodations.Checked then
            strBody = strBody & "<p>INTERPRETERS</p>"            
                  If americansign.Checked Then
                        strBody = strBody & "American Sign: Yes<br>"
                  Else
                        strBody = strBody & "American Sign: No<br>"
                  End If
                  If english.Checked = true
                        strBody = strBody & "English Sign: Yes<br>"
                  Else
                     strBody = strBody & "English Sign: No<br>"
                  End If
                  If tactile.Checked = true
                        strBody = strBody & "Tactile Interpreter: Yes<br>"
                  Else
                     strBody = strBody & "Tactile Interpreter: No<br>"
                  End If
                  If voice.Checked = true
                        strBody = strBody & "Voice Interpreter: Yes<br>"
                  Else
                     strBody = strBody & "Voice Interpreter: No<br>"
                  End If
                  If cart.Checked = true
                        strBody = strBody & "CART: Yes<br>"
                  Else
                      strBody = strBody & "CART: No<br>"
                  End If
                  If assistivelisteningdevices.Checked = true
                        strBody = strBody & "Assistive Listening Devices: Yes<br>"
                strBody = strBody & assistivelisteningdevicesexp.Text & "<br>"
                  Else
                     strBody = strBody & "Assistive Listening Devices: No<br>"
                  End If
                  
                  If otherint.Checked = true
                        strBody = strBody & "Other: Yes<br>"
                strBody = strBody & otherintexp.Text & "<br>"
                  Else
                     strBody = strBody & "Other: No<br>"
                  End If                  
           

            'Other Accommodations
                  If diet.Checked = true
                        strBody = strBody & "Diet: Yes<br>"
                strBody = strBody & dietexp.Text & "<br>"  
                  Else
                      strBody = strBody & "Diet: No<br>"
                  End If
                  
            'Meeting Material
            strBody = strBody & "<p>MEETING MATERIALS</p>"
                  If braille.Checked = true
                        strBody = strBody & "Braille: Yes<br>"
                  Else
                      strBody = strBody & "Braille: No<br>"
                  End If
                  If cd.Checked = true
                        strBody = strBody & "CD: Yes<br>"
                  Else
                      strBody = strBody & "CD: No<br>"
                  End If
                  If largeprint.Checked = true
                        strBody = strBody & "Large Print: Yes<br>"
                  Else
                      strBody = strBody & "Large Print: No<br>"
                  End If                  
                  If othermeet.Checked = true
                        strBody = strBody & "Other Meeting Materials: Yes<br>"
                strBody = strBody & othermeetexp.Text & "<br>"
                  Else
                      strBody = strBody & "Other Meeting Materials: No<br>"
                  End If                  
           
        End if
       
        'Hotel Accommodations
        If ddlRole.SelectedValue = 1 then
            strBody = strBody & "<p>HOTEL ACCOMMODATIONS</p>"            
            If dropMonth.SelectedValue = "" then
                strBody = strBody & "Arrival Date: N/A<br>"             
            Else            
                strBody = strBody & "Arrival Date: " & dropMonth.SelectedValue & "/" & dropDay.SelectedValue & "/" & dropYear.SelectedValue & "<br>"                                   
            End if
            If dropMonth2.SelectedValue = "" then
                strBody = strBody & "Departure Date: N/A<br>"                
            Else
                strBody = strBody & "Departure Date: " & dropMonth2.SelectedValue & "/" & dropDay2.SelectedValue & "/" & dropYear2.SelectedValue & "<br>"                                                        
            End if
                  If dblbeds.Checked = true
                        strBody = strBody & "Two Double Beds: Yes<br>"
                  Else
                      strBody = strBody & "Two Double Beds: No<br>"
                  End If
                  If queen.Checked = true
                        strBody = strBody & "Queen-Size Beds: Yes<br>"
                  Else
                      strBody = strBody & "Queen-Size Bed: No<br>"
                  End If
                  If bathtub.Checked = true
                        strBody = strBody & "Accessible Room with Bathtub and Grab Bars: Yes<br>"
                  Else
                      strBody = strBody & "Accessible Room with Bathtub and Grab Bars: No<br>"
                  End If
                  If rollin.Checked = true
                        strBody = strBody & "Accessible Room with Roll-In Shower: Yes<br>"
                  Else
                      strBody = strBody & "Accessible Room with Roll-In Shower: No<br>"
                  End If
                  If hearingkit.Checked = true
                        strBody = strBody & "Hotel Hearing Kit: Yes<br>"
                  Else
                      strBody = strBody & "Hotel Hearing Kit: No<br>"
                  End If
                  If Attendant1.Checked then
                        strBody = strBody & "Personal Care Attendant: Yes<br>"
                  Else
                      strBody = strBody & "Personal Care Attendant: No<br>"
                  End if
                  If adjoiningroom1.Checked then
                        strBody = strBody & "Do you require an adjoining room: Yes<br>"
                  Else
                      strBody = strBody & "Do you require an adjoining room: No<br>"
                  End if                  
                  If Dog1.Checked then
                        strBody = strBody & "Service Dog: Yes<br>"
                  Else
                      strBody = strBody & "Service Dog: No<br>"
                  End if
                  If travelinstructions.Checked = true then
                        strBody = strBody & "Special Instructions/Requests: Yes<br>"
                strBody = strBody & travelinstructionsexp.Text & "<br>"
                  Else
                      strBody = strBody & "Special Instructions/Requests: No<br>"
                  End If
                  
            'Ground Transportation
            strBody = strBody & "<p>GROUND TRANSPORTATION</p>"
                  If AccessibleV1.Checked then            
                        strBody = strBody & "Do You Require a Wheelchair Accessible Van: Yes<br>"                  
                  Else
                      strBody = strBody & "Do You Require a Wheelchair Accessible Van: No<br>"
                  End if
                 strBody = strBody & "Special Instructions:<br>"  & travelinstructionsexp.Text & "<br>"
                  
                  'Audiovisual Requirements
            strBody = strBody & "<p>AUDIOVISUAL REQUIREMENTS</p>"
                  If overhead.Checked = true then
                        strBody = strBody & "Overhead Projector: Yes<br>"                  
                  Else
                      strBody = strBody & "Overhead Projector: No<br>"
                  End If
                  If pointer.Checked = true then
                        strBody = strBody & "Pointer: Yes<br>"                  
                  Else
                      strBody = strBody & "Pointer: No<br>"
                  End If
                  If slide.Checked = true then
                        strBody = strBody & "Slide Projector: Yes<br>"                  
                  Else
                      strBody = strBody & "Slide Projector: No<br>"
                  End If
                  If flipchart.Checked = true then
                        strBody = strBody & "Flipchart: Yes<br>"                  
                  Else
                      strBody = strBody & "Flipchart: No<br>"
                  End If
                  If lcd.Checked = true then
                        strBody = strBody & "LCD Power Point Projector: Yes<br>"                  
                  Else
                      strBody = strBody & "LCD Power Point Projector: No<br>"
                  End If
                  If podium.Checked = true then
                        strBody = strBody & "Podium: Yes<br>"                  
                  Else
                      strBody = strBody & "Podium: No<br>"
                  End If
                  If mic.Checked = true then
                        strBody = strBody & "Lavaliere Microphone: Yes<br>"                  
                  Else
                      strBody = strBody & "Lavaliere Microphone: No<br>"
                  End If
                  If otheraudiovisual.Checked = true then
                        strBody = strBody & "Other: Yes<br>"
                strBody = strBody & otheraudiovisualexp.Text & "<br>"                  
                  Else
                      strBody = strBody & "Other: No<br>"
                  End If            
                  
        End if
       
        strBody = strBody &  "</p>"
            
        objMail.Body =  strBody        
        ' ** SMTP PORT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25") 'Put port number here
        ' ** CDO PORT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2")
          ' ** TIMEOUT **
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", "60")

        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "x")
        objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "x")  

        System.Web.Mail.SmtpMail.SmtpServer = "x"
        System.Web.Mail.SmtpMail.Send(objMail)
              
        objMail = Nothing
Ok thats all seems fair enough can you supply a copy of the result text (or preferably the whole message and headers (censored as neccesary) for the email) so i can see where the "!" are appearing.

Im pretty sure its because you need to UTF8 (or UTF7) encode the strbody text but the output may yield more clues.


but for now heres a quick hint... (and please do this if you have a few minutes)

instead of ....

 If voice.Checked = true
                    strBody = strBody & "Voice Interpreter: Yes<br>"
               Else
                  strBody = strBody & "Voice Interpreter: No<br>"
               End If

you can do

strbody=strbody & "Voice Interpreter: " & iif (Voice.Checked=true,"Yes","No") & "<br>"

and

 If otheraudiovisual.Checked = true then
                    strBody = strBody & "Other: Yes<br>"
                strBody = strBody & otheraudiovisualexp.Text & "<br>"                  
               Else
                   strBody = strBody & "Other: No<br>"
               End If      

you can do

strbody=strbody & "Other: " & iif(otheraudiovisual.checked=true ,"Yes<br>" & otheraudiovisualexp.text & "<br>", "No<br>")

which will quickly remove lots of the clutter (i.e. about 70% of the lines ) from your code...
Thanks for the tip.  I will incorporate that when I have some time.

Here's a sample of some of the email text:
\
Name: Karen Needels
Role: Participant
Attendance: Both Days
Degree: Ph.D.
Title: Senior Re! searcher
Org: Mathematica Policy Research, Inc.
Address: XXX Forbes Avenue
Address2:
City: Pittsburgh
Phone: xxx-xxx-xxxx
Phone Ext:
Fax: xxx-xxx-xxxxx
TTY:
ASKER CERTIFIED SOLUTION
Avatar of lojk
lojk
Flag of United Kingdom of Great Britain and Northern Ireland 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