H
Hugh Self Taught
Guest
Hi Gurus,
I've copied & modified my VBA code to send an email via MS Outlook. In the Access DB the Outlook email body from the email form would appear as formatted in the textbox on the form but I can't get that to happen in VB.Net
The textbox is multiline & when I type in it & press enter key it does a line feed as expected but that doesn't carry through to the email body where it's just a long line of text.
Here are the relevant parts of code from the form: The calling parameters are Subject, emailbody, display email, ishtmlformat, if embedded, to address, cc address, bccaddress, attachments, signature, email account
Dim strSignat As String = My.Settings.EmailSignature, strDefAcc As String = My.Settings.DefaultEmailAcc, txtMsg As String = System.Net.WebUtility.HtmlEncode(txtBody.Text)
If strSendTo.Length > 0 Then
If Tag = 1 Then
EmailAsHtml(txtSubject.Text, txtMsg, True, False, If(String.IsNullOrEmpty(txtEmbedded.Text), False, True),,, strSendTo.ToString,, txtAttach.Text, strSignat, strDefAcc)
And in a module
Function EmailAsHtml(strSubj As String, strBody As String, blnDisplayEmail As Boolean, IsHtmlFormat As Boolean, Embedded As Boolean, Optional strAddr As String = "", Optional strAddrCC As String = "", Optional strAddrBCC As String = "", Optional strRecpt As String = "", Optional strAttach As String = "", Optional strSignature As String = "", Optional strEmailAccount As String = "")
Dim strSendAcc As String = ""
With oMail
.Subject = strSubj
If IsHtmlFormat And Embedded = True Then
.HTMLBody = strBody & "<br><br>" & .HTMLBody & "<br>" & Signature
ElseIf IsHtmlFormat = False And Embedded = True Then
.HTMLBody = WebUtility.HtmlEncode(strBody) & "<br><br>" & WebUtility.HtmlEncode(.HTMLBody) & "<br>" & Signature
ElseIf IsHtmlFormat Then
.HTMLBody = strBody & "<br>" & Signature
Else
.HTMLBody = WebUtility.HtmlEncode(strBody) & "<br>" & Signature 'This will convert the plain text string to an Html string
End If
.SendUsingAccount = oNameSpace.Session.Accounts.Item(strSendAcc)
I've tried everything I can think of & am still stumped. Anyone got an idea what I'm missing or why the behaviour should be different? Any pointers & help greatly appreciated
Continue reading...
I've copied & modified my VBA code to send an email via MS Outlook. In the Access DB the Outlook email body from the email form would appear as formatted in the textbox on the form but I can't get that to happen in VB.Net
The textbox is multiline & when I type in it & press enter key it does a line feed as expected but that doesn't carry through to the email body where it's just a long line of text.
Here are the relevant parts of code from the form: The calling parameters are Subject, emailbody, display email, ishtmlformat, if embedded, to address, cc address, bccaddress, attachments, signature, email account
Dim strSignat As String = My.Settings.EmailSignature, strDefAcc As String = My.Settings.DefaultEmailAcc, txtMsg As String = System.Net.WebUtility.HtmlEncode(txtBody.Text)
If strSendTo.Length > 0 Then
If Tag = 1 Then
EmailAsHtml(txtSubject.Text, txtMsg, True, False, If(String.IsNullOrEmpty(txtEmbedded.Text), False, True),,, strSendTo.ToString,, txtAttach.Text, strSignat, strDefAcc)
And in a module
Function EmailAsHtml(strSubj As String, strBody As String, blnDisplayEmail As Boolean, IsHtmlFormat As Boolean, Embedded As Boolean, Optional strAddr As String = "", Optional strAddrCC As String = "", Optional strAddrBCC As String = "", Optional strRecpt As String = "", Optional strAttach As String = "", Optional strSignature As String = "", Optional strEmailAccount As String = "")
Dim strSendAcc As String = ""
With oMail
.Subject = strSubj
If IsHtmlFormat And Embedded = True Then
.HTMLBody = strBody & "<br><br>" & .HTMLBody & "<br>" & Signature
ElseIf IsHtmlFormat = False And Embedded = True Then
.HTMLBody = WebUtility.HtmlEncode(strBody) & "<br><br>" & WebUtility.HtmlEncode(.HTMLBody) & "<br>" & Signature
ElseIf IsHtmlFormat Then
.HTMLBody = strBody & "<br>" & Signature
Else
.HTMLBody = WebUtility.HtmlEncode(strBody) & "<br>" & Signature 'This will convert the plain text string to an Html string
End If
.SendUsingAccount = oNameSpace.Session.Accounts.Item(strSendAcc)
I've tried everything I can think of & am still stumped. Anyone got an idea what I'm missing or why the behaviour should be different? Any pointers & help greatly appreciated
Continue reading...