I have a piece of code that sends out emails, it works absolutely fine except when I want to include crlfs in the body. It replaces them with spaces. Well actually, the first crlf works OK, but the ones after the first do not. I wonder if that is important?
In other applications, I'm inserting the emails into an Oracle table, then using an email application that runs every 30 mins to check this table and send out any pending emails. When I am originally inserting the email into the table, I'm using the vbCrLf character if that makes any difference.
The code is below and if you want to test it, you can use something like this for the body of the email:
Customer ID: 123456
Customer Name: TOOL & EQUIPMENT SUPPLIES
Order ID: C12345
Order Amount: $500.00
Requested By: BRANEY
If you notice in the code below, the debug.print line checks what it is right before it sends and it seems to be perfectly fine at this point. I've also tried it as an HTML email and that doesnt work either.
Private Function SendEmail(ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, ByVal strAttachment As String, ByVal strFrom As String, Optional ByVal CCTo As String = "") As Boolean
' Take the parameters passed in the function and create an email message
Dim oMessage As MailMessage = New MailMessage(strFrom, strTo, strSubject, strBody)
oMessage.IsBodyHtml = False
' Does the message have a cc address?
If CCTo <> "" Then
' Does the message have an attachment?
Dim oAttachment As Attachment = Nothing
If strAttachment <> "" Then
oAttachment = New Attachment(strAttachment)
Dim oClient As New SmtpClient(My.Settings.SMTPServer, My.Settings.PortNumber)
' Release the attachment if it exists
If oAttachment IsNot Nothing Then
oAttachment = Nothing
' Email sent successfully
Catch ex As System.Net.WebException
' Email Failed