Results 1 to 10 of 10

Thread: [RESOLVED] vbcrlf and vbnewline problem

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: vbcrlf and vbnewline problem

    Yep, that fixed it. Thanks! I checked out my code and I didn't put in .IsBodyHtml but i have now and I put it as html. Everything is formatted correctly now.
    Quote Originally Posted by kevininstructor View Post
    Sounds like you are doing HTML body for your email message which means </br> will be your line break

    So something like this would fix your line break issue. The following can not be used by copy/paste as it has variables that you do not have.

    Code:
       Sub SendMessage()
            Try
                Using TheMessage As New System.Net.Mail.MailMessage()
                    TheMessage.From = New System.Net.Mail.MailAddress(FromAddress)
                    TheMessage.To.Add(New System.Net.Mail.MailAddress(SendToAddress))
    
                    TheMessage.Subject = ApplicationName
    
                    TheMessage.Body = String.Format( _
                        "This is an automated email, please do not respond<br><br>An " & _
                        "exception ocurred in <br><span style=""font-weight: bold; padding-left:20px;" & _
                        "padding-right:5px"">Application name</span>{0}<br>" & _
                        "<span style=""font-weight: bold; padding-left: 5px;padding-right:5px"">" & _
                        "Application Version</span>{1}<br><span style=""font-weight: bold; " & _
                        "padding-left: 70px;padding-right:5px"">Exception</span>{2}", _
                        ApplicationName, ApplicationVersion, ErrorMessage)
                    TheMessage.IsBodyHtml = True
                    Dim MailClient As New System.Net.Mail.SmtpClient(SmtpClient)
                    MailClient.UseDefaultCredentials = True
                    MailClient.Send(TheMessage)
                End Using
            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try
        End Sub

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] vbcrlf and vbnewline problem

    I have gotten it to work. I even color coded the severity within the e-mail body. One thing that is baffling is that I have set the message table to 100&#37; (line 34) and the form itself can have a maximum of 8,000 characters. The e-mail shows the message (txtMessage) in one line and it's not all visible without having to scroll to the right. Any suggestions? Do you think I might have to WordWrap it or something?

    Code is below:
    vb Code:
    1. <CLSCompliant(True)> Private Sub cmdSend_Click(ByVal sender As System.Object, _
    2.                                                    ByVal e As System.EventArgs) Handles cmdSend.Click
    3.  
    4.         Try
    5.             'Send the e-mail.
    6.             Dim ToEmailAddress As New MailAddress("[email protected]", "Your Name")
    7.             Dim FromEmailAddress As New MailAddress("" & txtEmailAddress.Text.Trim.ToString & "", "" & ProductName & " User")
    8.             Dim sMessageSubject As String = "[" & cboSeverity.Text.Trim & " Severity] " & ProductName & " User Message."
    9.             Dim sMessage As String = txtMessage.Text.Trim
    10.             Dim sMessageBody As String
    11.  
    12.             Dim sColorCodeSeverity As String = Nothing
    13.  
    14.             Select Case cboSeverity.SelectedItem.ToString
    15.                 Case Is = "Low" '#00CC00 (Green)
    16.                     sColorCodeSeverity = "<font color=#00CC00>Low</font>"
    17.                 Case Is = "Medium" '#0099CC (Blue)
    18.                     sColorCodeSeverity = "<font color=#0099CC>Medium</font>"
    19.                 Case Is = "High" '#FF3300 (Red)
    20.                     sColorCodeSeverity = "<b><font color=#FF3300>High</font></b>"
    21.                 Case Is = "Urgent" '#FF6699 (Pink)
    22.                     sColorCodeSeverity = "<b><font color=#FF6699>Urgent</font></b>"
    23.                 Case Is = "Critical" '#993366 (Purple)
    24.                     sColorCodeSeverity = "<b><font color=#993366>Critical</font></b>"
    25.             End Select
    26.  
    27.             sMessageBody = "<font color=red><b>REMINDER:</b> If the end user has requested a reply e-mail, they were promised an e-mail within 48 hours.</font><br><br>" & _
    28.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    29.                            "<tr>" & _
    30.                            "<td width=15%>Client Name:</td><td>" & txtName.Text.Trim & "</td></tr><tr>" & _
    31.                            "<td width=15%>Contact Reason:</td><td>" & cboContactReason.SelectedItem.ToString & "</td>" & _
    32.                            "</tr><tr>" & _
    33.                            "<td width=15%>Requires a reply:</td><td>" & cboReplyBack.SelectedItem.ToString & "</td></tr><tr>" & _
    34.                            "<td width=15%>Severity:</td><td>" & sColorCodeSeverity & "</td></tr></table><br>" & _
    35.                            "<b>E-MAIL MESSAGE:</b>" & _
    36.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    37.                            "<tr><td>" & sMessage & "</td></tr></table><br>" & _
    38.                            "<b>MACHINE INFORMATION:</b>" & _
    39.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=42% cellpadding=3 cellspacing=3>" & _
    40.                            "<tr>" & _
    41.                            "<td>Computer Name:</td><td>" & My.Computer.Name & "</td>" & _
    42.                            "</tr><tr>" & _
    43.                            "<td>Available Physical Memory:</td><td>" & My.Computer.Info.AvailablePhysicalMemory & "</td>" & _
    44.                            "<tr>" & _
    45.                            "<td>Available Virtual Memory:</td><td>" & My.Computer.Info.AvailableVirtualMemory & "</td>" & _
    46.                            "</tr><tr>" & _
    47.                            "<td>Total Physical Memory:</td><td>" & My.Computer.Info.TotalPhysicalMemory & "</td>" & _
    48.                            "</tr><tr>" & _
    49.                            "<td>Total Virtual Memory:</td><td>" & My.Computer.Info.TotalVirtualMemory & "</td>" & _
    50.                            "</tr><tr>" & _
    51.                            "<td>Operating System Full Name:</td><td>" & My.Computer.Info.OSFullName & "</td>" & _
    52.                            "</tr><tr>" & _
    53.                            "<td>Operating System Platform:</td><td>" & My.Computer.Info.OSPlatform & "</td>" & _
    54.                            "</tr><tr>" & _
    55.                            "<td>Operating System Version:</td><td>" & My.Computer.Info.OSVersion & "</td>" & _
    56.                            "</tr>" & _
    57.                            "</table><br>" & _
    58.                            "<b>APPLICATION INFORMATION:</b>" & "<br>" & _
    59.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    60.                            "<tr>" & _
    61.                            "<td>Application Name:</td><td>" & My.Application.Info.ProductName & "</td>" & _
    62.                            "</tr><tr>" & _
    63.                            "<td>Common Application Data Path:</td><td>" & CommonAppDataPath & "</td>" & _
    64.                            "</tr><tr>" & _
    65.                            "<td>Executable Path:</td><td>" & ExecutablePath & "</td>" & _
    66.                            "</tr><tr>" & _
    67.                            "<td>Local User Application Data Path:</td><td>" & LocalUserAppDataPath & "</td>" & _
    68.                            "</tr><tr>" & _
    69.                            "<td>Startup Path:</td><td>" & StartupPath & "</td>" & _
    70.                            "</tr><tr>" & _
    71.                            "<td>User Application Data Path:</td><td>" & UserAppDataPath & "</td></tr></table>"
    72.  
    73.             Dim MailPriority As New Net.Mail.MailPriority
    74.  
    75.             Select Case cboPriority.Text
    76.                 Case "Low"
    77.                     MailPriority = Net.Mail.MailPriority.Low
    78.                 Case "Normal"
    79.                     MailPriority = Net.Mail.MailPriority.Normal
    80.                 Case "High"
    81.                     MailPriority = Net.Mail.MailPriority.High
    82.             End Select
    83.  
    84.             clsSendMail.SendMail(sMessageBody, _
    85.                                  sMessageSubject, _
    86.                                  Net.Mail.DeliveryNotificationOptions.OnFailure, _
    87.                                  MailPriority, _
    88.                                  ToEmailAddress, _
    89.                                  FromEmailAddress, _
    90.                                  Nothing, _
    91.                                  Nothing, _
    92.                                  Nothing)
    93.         Catch ex As InvalidCastException
    94.             MessageBox.Show(ex.Message, _
    95.                             "Invalid Cast Exception.", _
    96.                             MessageBoxButtons.OK, _
    97.                             MessageBoxIcon.Error, _
    98.                             MessageBoxDefaultButton.Button1, _
    99.                             MessageBoxOptions.DefaultDesktopOnly, _
    100.                             False)
    101.         Catch ex As FormatException
    102.             MessageBox.Show(ex.Message, _
    103.                 "Format Exception.", _
    104.                 MessageBoxButtons.OK, _
    105.                 MessageBoxIcon.Error, _
    106.                 MessageBoxDefaultButton.Button1, _
    107.                 MessageBoxOptions.DefaultDesktopOnly, _
    108.                 False)
    109.         Finally
    110.             If cboReplyBack.Text = "Yes" Then
    111.                 MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!" & vbNewLine & _
    112.                                 "You will hear from us via e-mail within 48 hours.", _
    113.                                 "E-mail Successfully Sent.", _
    114.                                 MessageBoxButtons.OK, _
    115.                                 MessageBoxIcon.Information, _
    116.                                 MessageBoxDefaultButton.Button1, _
    117.                                 MessageBoxOptions.DefaultDesktopOnly, _
    118.                                 False)
    119.             Else 'No.
    120.                 MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!", _
    121.                                 "E-mail Successfully Sent.", _
    122.                                 MessageBoxButtons.OK, _
    123.                                 MessageBoxIcon.Information, _
    124.                                 MessageBoxDefaultButton.Button1, _
    125.                                 MessageBoxOptions.DefaultDesktopOnly, _
    126.                                 False)
    127.             End If
    128.         End Try
    129.     End Sub

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: [RESOLVED] vbcrlf and vbnewline problem

    Quote Originally Posted by BrailleSchool View Post
    I have gotten it to work. I even color coded the severity within the e-mail body. One thing that is baffling is that I have set the message table to 100% (line 34) and the form itself can have a maximum of 8,000 characters. The e-mail shows the message (txtMessage) in one line and it's not all visible without having to scroll to the right. Any suggestions? Do you think I might have to WordWrap it or something?

    Code is below:
    vb Code:
    1. <CLSCompliant(True)> Private Sub cmdSend_Click(ByVal sender As System.Object, _
    2.                                                    ByVal e As System.EventArgs) Handles cmdSend.Click
    3.  
    4.         Try
    5.             'Send the e-mail.
    6.             Dim ToEmailAddress As New MailAddress("[email protected]", "Your Name")
    7.             Dim FromEmailAddress As New MailAddress("" & txtEmailAddress.Text.Trim.ToString & "", "" & ProductName & " User")
    8.             Dim sMessageSubject As String = "[" & cboSeverity.Text.Trim & " Severity] " & ProductName & " User Message."
    9.             Dim sMessage As String = txtMessage.Text.Trim
    10.             Dim sMessageBody As String
    11.  
    12.             Dim sColorCodeSeverity As String = Nothing
    13.  
    14.             Select Case cboSeverity.SelectedItem.ToString
    15.                 Case Is = "Low" '#00CC00 (Green)
    16.                     sColorCodeSeverity = "<font color=#00CC00>Low</font>"
    17.                 Case Is = "Medium" '#0099CC (Blue)
    18.                     sColorCodeSeverity = "<font color=#0099CC>Medium</font>"
    19.                 Case Is = "High" '#FF3300 (Red)
    20.                     sColorCodeSeverity = "<b><font color=#FF3300>High</font></b>"
    21.                 Case Is = "Urgent" '#FF6699 (Pink)
    22.                     sColorCodeSeverity = "<b><font color=#FF6699>Urgent</font></b>"
    23.                 Case Is = "Critical" '#993366 (Purple)
    24.                     sColorCodeSeverity = "<b><font color=#993366>Critical</font></b>"
    25.             End Select
    26.  
    27.             sMessageBody = "<font color=red><b>REMINDER:</b> If the end user has requested a reply e-mail, they were promised an e-mail within 48 hours.</font><br><br>" & _
    28.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    29.                            "<tr>" & _
    30.                            "<td width=15%>Client Name:</td><td>" & txtName.Text.Trim & "</td></tr><tr>" & _
    31.                            "<td width=15%>Contact Reason:</td><td>" & cboContactReason.SelectedItem.ToString & "</td>" & _
    32.                            "</tr><tr>" & _
    33.                            "<td width=15%>Requires a reply:</td><td>" & cboReplyBack.SelectedItem.ToString & "</td></tr><tr>" & _
    34.                            "<td width=15%>Severity:</td><td>" & sColorCodeSeverity & "</td></tr></table><br>" & _
    35.                            "<b>E-MAIL MESSAGE:</b>" & _
    36.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    37.                            "<tr><td>" & sMessage & "</td></tr></table><br>" & _
    38.                            "<b>MACHINE INFORMATION:</b>" & _
    39.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=42% cellpadding=3 cellspacing=3>" & _
    40.                            "<tr>" & _
    41.                            "<td>Computer Name:</td><td>" & My.Computer.Name & "</td>" & _
    42.                            "</tr><tr>" & _
    43.                            "<td>Available Physical Memory:</td><td>" & My.Computer.Info.AvailablePhysicalMemory & "</td>" & _
    44.                            "<tr>" & _
    45.                            "<td>Available Virtual Memory:</td><td>" & My.Computer.Info.AvailableVirtualMemory & "</td>" & _
    46.                            "</tr><tr>" & _
    47.                            "<td>Total Physical Memory:</td><td>" & My.Computer.Info.TotalPhysicalMemory & "</td>" & _
    48.                            "</tr><tr>" & _
    49.                            "<td>Total Virtual Memory:</td><td>" & My.Computer.Info.TotalVirtualMemory & "</td>" & _
    50.                            "</tr><tr>" & _
    51.                            "<td>Operating System Full Name:</td><td>" & My.Computer.Info.OSFullName & "</td>" & _
    52.                            "</tr><tr>" & _
    53.                            "<td>Operating System Platform:</td><td>" & My.Computer.Info.OSPlatform & "</td>" & _
    54.                            "</tr><tr>" & _
    55.                            "<td>Operating System Version:</td><td>" & My.Computer.Info.OSVersion & "</td>" & _
    56.                            "</tr>" & _
    57.                            "</table><br>" & _
    58.                            "<b>APPLICATION INFORMATION:</b>" & "<br>" & _
    59.                            "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
    60.                            "<tr>" & _
    61.                            "<td>Application Name:</td><td>" & My.Application.Info.ProductName & "</td>" & _
    62.                            "</tr><tr>" & _
    63.                            "<td>Common Application Data Path:</td><td>" & CommonAppDataPath & "</td>" & _
    64.                            "</tr><tr>" & _
    65.                            "<td>Executable Path:</td><td>" & ExecutablePath & "</td>" & _
    66.                            "</tr><tr>" & _
    67.                            "<td>Local User Application Data Path:</td><td>" & LocalUserAppDataPath & "</td>" & _
    68.                            "</tr><tr>" & _
    69.                            "<td>Startup Path:</td><td>" & StartupPath & "</td>" & _
    70.                            "</tr><tr>" & _
    71.                            "<td>User Application Data Path:</td><td>" & UserAppDataPath & "</td></tr></table>"
    72.  
    73.             Dim MailPriority As New Net.Mail.MailPriority
    74.  
    75.             Select Case cboPriority.Text
    76.                 Case "Low"
    77.                     MailPriority = Net.Mail.MailPriority.Low
    78.                 Case "Normal"
    79.                     MailPriority = Net.Mail.MailPriority.Normal
    80.                 Case "High"
    81.                     MailPriority = Net.Mail.MailPriority.High
    82.             End Select
    83.  
    84.             clsSendMail.SendMail(sMessageBody, _
    85.                                  sMessageSubject, _
    86.                                  Net.Mail.DeliveryNotificationOptions.OnFailure, _
    87.                                  MailPriority, _
    88.                                  ToEmailAddress, _
    89.                                  FromEmailAddress, _
    90.                                  Nothing, _
    91.                                  Nothing, _
    92.                                  Nothing)
    93.         Catch ex As InvalidCastException
    94.             MessageBox.Show(ex.Message, _
    95.                             "Invalid Cast Exception.", _
    96.                             MessageBoxButtons.OK, _
    97.                             MessageBoxIcon.Error, _
    98.                             MessageBoxDefaultButton.Button1, _
    99.                             MessageBoxOptions.DefaultDesktopOnly, _
    100.                             False)
    101.         Catch ex As FormatException
    102.             MessageBox.Show(ex.Message, _
    103.                 "Format Exception.", _
    104.                 MessageBoxButtons.OK, _
    105.                 MessageBoxIcon.Error, _
    106.                 MessageBoxDefaultButton.Button1, _
    107.                 MessageBoxOptions.DefaultDesktopOnly, _
    108.                 False)
    109.         Finally
    110.             If cboReplyBack.Text = "Yes" Then
    111.                 MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!" & vbNewLine & _
    112.                                 "You will hear from us via e-mail within 48 hours.", _
    113.                                 "E-mail Successfully Sent.", _
    114.                                 MessageBoxButtons.OK, _
    115.                                 MessageBoxIcon.Information, _
    116.                                 MessageBoxDefaultButton.Button1, _
    117.                                 MessageBoxOptions.DefaultDesktopOnly, _
    118.                                 False)
    119.             Else 'No.
    120.                 MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!", _
    121.                                 "E-mail Successfully Sent.", _
    122.                                 MessageBoxButtons.OK, _
    123.                                 MessageBoxIcon.Information, _
    124.                                 MessageBoxDefaultButton.Button1, _
    125.                                 MessageBoxOptions.DefaultDesktopOnly, _
    126.                                 False)
    127.             End If
    128.         End Try
    129.     End Sub
    When coding in web projects I've had to use the following style for the Body tag to get a table to recognize the 100% width. Not sure if email providers recognize the body tag.

    Code:
    body {margin:0;padding:0;}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] vbcrlf and vbnewline problem

    Quote Originally Posted by kevininstructor View Post
    When coding in web projects I've had to use the following style for the Body tag to get a table to recognize the 100% width. Not sure if email providers recognize the body tag.

    Code:
    body {margin:0;padding:0;}
    Thanks, got it working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width