|
-
Jan 23rd, 2011, 08:18 AM
#1
Thread Starter
PowerPoster
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.
 Originally Posted by kevininstructor
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
-
Jan 23rd, 2011, 10:04 AM
#2
Thread Starter
PowerPoster
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% (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:
<CLSCompliant(True)> Private Sub cmdSend_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdSend.Click Try 'Send the e-mail. Dim FromEmailAddress As New MailAddress("" & txtEmailAddress.Text.Trim.ToString & "", "" & ProductName & " User") Dim sMessageSubject As String = "[" & cboSeverity.Text.Trim & " Severity] " & ProductName & " User Message." Dim sMessage As String = txtMessage.Text.Trim Dim sMessageBody As String Dim sColorCodeSeverity As String = Nothing Select Case cboSeverity.SelectedItem.ToString Case Is = "Low" '#00CC00 (Green) sColorCodeSeverity = "<font color=#00CC00>Low</font>" Case Is = "Medium" '#0099CC (Blue) sColorCodeSeverity = "<font color=#0099CC>Medium</font>" Case Is = "High" '#FF3300 (Red) sColorCodeSeverity = "<b><font color=#FF3300>High</font></b>" Case Is = "Urgent" '#FF6699 (Pink) sColorCodeSeverity = "<b><font color=#FF6699>Urgent</font></b>" Case Is = "Critical" '#993366 (Purple) sColorCodeSeverity = "<b><font color=#993366>Critical</font></b>" End Select 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>" & _ "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _ "<tr>" & _ "<td width=15%>Client Name:</td><td>" & txtName.Text.Trim & "</td></tr><tr>" & _ "<td width=15%>Contact Reason:</td><td>" & cboContactReason.SelectedItem.ToString & "</td>" & _ "</tr><tr>" & _ "<td width=15%>Requires a reply:</td><td>" & cboReplyBack.SelectedItem.ToString & "</td></tr><tr>" & _ "<td width=15%>Severity:</td><td>" & sColorCodeSeverity & "</td></tr></table><br>" & _ "<b>E-MAIL MESSAGE:</b>" & _ "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _ "<tr><td>" & sMessage & "</td></tr></table><br>" & _ "<b>MACHINE INFORMATION:</b>" & _ "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=42% cellpadding=3 cellspacing=3>" & _ "<tr>" & _ "<td>Computer Name:</td><td>" & My.Computer.Name & "</td>" & _ "</tr><tr>" & _ "<td>Available Physical Memory:</td><td>" & My.Computer.Info.AvailablePhysicalMemory & "</td>" & _ "<tr>" & _ "<td>Available Virtual Memory:</td><td>" & My.Computer.Info.AvailableVirtualMemory & "</td>" & _ "</tr><tr>" & _ "<td>Total Physical Memory:</td><td>" & My.Computer.Info.TotalPhysicalMemory & "</td>" & _ "</tr><tr>" & _ "<td>Total Virtual Memory:</td><td>" & My.Computer.Info.TotalVirtualMemory & "</td>" & _ "</tr><tr>" & _ "<td>Operating System Full Name:</td><td>" & My.Computer.Info.OSFullName & "</td>" & _ "</tr><tr>" & _ "<td>Operating System Platform:</td><td>" & My.Computer.Info.OSPlatform & "</td>" & _ "</tr><tr>" & _ "<td>Operating System Version:</td><td>" & My.Computer.Info.OSVersion & "</td>" & _ "</tr>" & _ "</table><br>" & _ "<b>APPLICATION INFORMATION:</b>" & "<br>" & _ "<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _ "<tr>" & _ "<td>Application Name:</td><td>" & My.Application.Info.ProductName & "</td>" & _ "</tr><tr>" & _ "<td>Common Application Data Path:</td><td>" & CommonAppDataPath & "</td>" & _ "</tr><tr>" & _ "<td>Executable Path:</td><td>" & ExecutablePath & "</td>" & _ "</tr><tr>" & _ "<td>Local User Application Data Path:</td><td>" & LocalUserAppDataPath & "</td>" & _ "</tr><tr>" & _ "<td>Startup Path:</td><td>" & StartupPath & "</td>" & _ "</tr><tr>" & _ "<td>User Application Data Path:</td><td>" & UserAppDataPath & "</td></tr></table>" Dim MailPriority As New Net.Mail.MailPriority Select Case cboPriority.Text Case "Low" MailPriority = Net.Mail.MailPriority.Low Case "Normal" MailPriority = Net.Mail.MailPriority.Normal Case "High" MailPriority = Net.Mail.MailPriority.High End Select clsSendMail.SendMail(sMessageBody, _ sMessageSubject, _ Net.Mail.DeliveryNotificationOptions.OnFailure, _ MailPriority, _ ToEmailAddress, _ FromEmailAddress, _ Nothing, _ Nothing, _ Nothing) Catch ex As InvalidCastException MessageBox.Show(ex.Message, _ "Invalid Cast Exception.", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error, _ MessageBoxDefaultButton.Button1, _ MessageBoxOptions.DefaultDesktopOnly, _ False) Catch ex As FormatException MessageBox.Show(ex.Message, _ "Format Exception.", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error, _ MessageBoxDefaultButton.Button1, _ MessageBoxOptions.DefaultDesktopOnly, _ False) Finally If cboReplyBack.Text = "Yes" Then MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!" & vbNewLine & _ "You will hear from us via e-mail within 48 hours.", _ "E-mail Successfully Sent.", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information, _ MessageBoxDefaultButton.Button1, _ MessageBoxOptions.DefaultDesktopOnly, _ False) Else 'No. MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!", _ "E-mail Successfully Sent.", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information, _ MessageBoxDefaultButton.Button1, _ MessageBoxOptions.DefaultDesktopOnly, _ False) End If End Try End Sub
Last edited by BrailleSchool; Jan 23rd, 2011 at 10:39 AM.
Reason: Removed email address from code.
-
Jan 23rd, 2011, 11:02 AM
#3
Re: [RESOLVED] vbcrlf and vbnewline problem
 Originally Posted by BrailleSchool
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:
<CLSCompliant(True)> Private Sub cmdSend_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdSend.Click
Try
'Send the e-mail.
Dim FromEmailAddress As New MailAddress("" & txtEmailAddress.Text.Trim.ToString & "", "" & ProductName & " User")
Dim sMessageSubject As String = "[" & cboSeverity.Text.Trim & " Severity] " & ProductName & " User Message."
Dim sMessage As String = txtMessage.Text.Trim
Dim sMessageBody As String
Dim sColorCodeSeverity As String = Nothing
Select Case cboSeverity.SelectedItem.ToString
Case Is = "Low" '#00CC00 (Green)
sColorCodeSeverity = "<font color=#00CC00>Low</font>"
Case Is = "Medium" '#0099CC (Blue)
sColorCodeSeverity = "<font color=#0099CC>Medium</font>"
Case Is = "High" '#FF3300 (Red)
sColorCodeSeverity = "<b><font color=#FF3300>High</font></b>"
Case Is = "Urgent" '#FF6699 (Pink)
sColorCodeSeverity = "<b><font color=#FF6699>Urgent</font></b>"
Case Is = "Critical" '#993366 (Purple)
sColorCodeSeverity = "<b><font color=#993366>Critical</font></b>"
End Select
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>" & _
"<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
"<tr>" & _
"<td width=15%>Client Name:</td><td>" & txtName.Text.Trim & "</td></tr><tr>" & _
"<td width=15%>Contact Reason:</td><td>" & cboContactReason.SelectedItem.ToString & "</td>" & _
"</tr><tr>" & _
"<td width=15%>Requires a reply:</td><td>" & cboReplyBack.SelectedItem.ToString & "</td></tr><tr>" & _
"<td width=15%>Severity:</td><td>" & sColorCodeSeverity & "</td></tr></table><br>" & _
"<b>E-MAIL MESSAGE:</b>" & _
"<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
"<tr><td>" & sMessage & "</td></tr></table><br>" & _
"<b>MACHINE INFORMATION:</b>" & _
"<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=42% cellpadding=3 cellspacing=3>" & _
"<tr>" & _
"<td>Computer Name:</td><td>" & My.Computer.Name & "</td>" & _
"</tr><tr>" & _
"<td>Available Physical Memory:</td><td>" & My.Computer.Info.AvailablePhysicalMemory & "</td>" & _
"<tr>" & _
"<td>Available Virtual Memory:</td><td>" & My.Computer.Info.AvailableVirtualMemory & "</td>" & _
"</tr><tr>" & _
"<td>Total Physical Memory:</td><td>" & My.Computer.Info.TotalPhysicalMemory & "</td>" & _
"</tr><tr>" & _
"<td>Total Virtual Memory:</td><td>" & My.Computer.Info.TotalVirtualMemory & "</td>" & _
"</tr><tr>" & _
"<td>Operating System Full Name:</td><td>" & My.Computer.Info.OSFullName & "</td>" & _
"</tr><tr>" & _
"<td>Operating System Platform:</td><td>" & My.Computer.Info.OSPlatform & "</td>" & _
"</tr><tr>" & _
"<td>Operating System Version:</td><td>" & My.Computer.Info.OSVersion & "</td>" & _
"</tr>" & _
"</table><br>" & _
"<b>APPLICATION INFORMATION:</b>" & "<br>" & _
"<table border=0 bordercolor=#FFFFFF style=background-color:#FFFFFF width=100% cellpadding=3 cellspacing=3>" & _
"<tr>" & _
"<td>Application Name:</td><td>" & My.Application.Info.ProductName & "</td>" & _
"</tr><tr>" & _
"<td>Common Application Data Path:</td><td>" & CommonAppDataPath & "</td>" & _
"</tr><tr>" & _
"<td>Executable Path:</td><td>" & ExecutablePath & "</td>" & _
"</tr><tr>" & _
"<td>Local User Application Data Path:</td><td>" & LocalUserAppDataPath & "</td>" & _
"</tr><tr>" & _
"<td>Startup Path:</td><td>" & StartupPath & "</td>" & _
"</tr><tr>" & _
"<td>User Application Data Path:</td><td>" & UserAppDataPath & "</td></tr></table>"
Dim MailPriority As New Net.Mail.MailPriority
Select Case cboPriority.Text
Case "Low"
MailPriority = Net.Mail.MailPriority.Low
Case "Normal"
MailPriority = Net.Mail.MailPriority.Normal
Case "High"
MailPriority = Net.Mail.MailPriority.High
End Select
clsSendMail.SendMail(sMessageBody, _
sMessageSubject, _
Net.Mail.DeliveryNotificationOptions.OnFailure, _
MailPriority, _
ToEmailAddress, _
FromEmailAddress, _
Nothing, _
Nothing, _
Nothing)
Catch ex As InvalidCastException
MessageBox.Show(ex.Message, _
"Invalid Cast Exception.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, _
False)
Catch ex As FormatException
MessageBox.Show(ex.Message, _
"Format Exception.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, _
False)
Finally
If cboReplyBack.Text = "Yes" Then
MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!" & vbNewLine & _
"You will hear from us via e-mail within 48 hours.", _
"E-mail Successfully Sent.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, _
False)
Else 'No.
MessageBox.Show("Your e-mail message was successfully sent, " & txtName.Text.Trim & "!", _
"E-mail Successfully Sent.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, _
False)
End If
End Try
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;}
-
Jan 25th, 2011, 02:44 AM
#4
Thread Starter
PowerPoster
Re: [RESOLVED] vbcrlf and vbnewline problem
 Originally Posted by kevininstructor
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|