T
Thomas Kroljic
All,
In one of my Access application I have a form that allows the user to
send an email out to a prospective client. It uses text fields for email
address and subject line. I use a memo field for the body of the email. The
code is below.
Currently, I'm setting the email BodyFormat = olFormatHTML. This seems to
work best in my testing.
Questions:
1. Is this the best approach?
2. If I want to have a list of "canned" emails that the user can
select, what would be the best approach to this method.
a. Do I store the text of the email in a table/record and then read
the appropriate record (data) into a variable or .body
b. Do I just have a list of files (text files) that the user can select
and then move this data into the .body
I'm open to any suggestion. Thank you.
'create the actual email and send it out
'----------------------------------------
Dim AppOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set AppOutLook = CreateObject("Outlook.Application")
Dim xref As Hyperlink
' logon
Dim xnamemail As String
xnamemail = "Default"
Call AppOutLook.GetNamespace("MAPI").Logon(Profile:=xnamemail)
Set MailOutLook = AppOutLook.CreateItem(olMailItem)
Dim SecurityManager As New AddInExpress.OutlookSecurityManager
SecurityManager.ConnectTo AppOutLook
SecurityManager.DisableOOMWarnings = True
Dim xhtmlstring As String
'the following logic will insert a <br/> whenever a cr/lf appears
For X = 1 To Len(Me.txt_body)
If mID(Me.txt_body, X, 1) = Chr(13) Then
xhtmlstring = xhtmlstring + "<br />"
Else
xhtmlstring = xhtmlstring + mID(Me.txt_body, X, 1)
End If
Next X
With MailOutLook
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = Me.txt_to
.Subject = Me.txt_subject
If Me.txt_attachment <> "" And _
Not IsNull(Me.txt_attachment) Then
.Attachments.Add "d:\storemanagement\emailpdf\" & _
pEmailAttachment
End If
.HTMLBody = "<body>" & xhtmlstring & "<br />" & _
"<br />" & _
"<br />" & _
"<br />" & _
mEmpFullName & "<br />" & _
"<b>Company Name<b/> " & "<br />" & _
"Phone Number: " & mPhoneNumber & "<br />" & _
IIf(mFaxNumber <> "", "Fax Number: " & mFaxNumber &
"<br />", "") & _
"Visit us at <a
href=http://www.companyname.com>www.companyname.com</a> " & "<br />" & _
"</body>"
'.Display True
.Send
End With
SecurityManager.DisableOOMWarnings = False
'let's close the form and go home
DoCmd.Close acForm, "frmMailOut"
In one of my Access application I have a form that allows the user to
send an email out to a prospective client. It uses text fields for email
address and subject line. I use a memo field for the body of the email. The
code is below.
Currently, I'm setting the email BodyFormat = olFormatHTML. This seems to
work best in my testing.
Questions:
1. Is this the best approach?
2. If I want to have a list of "canned" emails that the user can
select, what would be the best approach to this method.
a. Do I store the text of the email in a table/record and then read
the appropriate record (data) into a variable or .body
b. Do I just have a list of files (text files) that the user can select
and then move this data into the .body
I'm open to any suggestion. Thank you.
'create the actual email and send it out
'----------------------------------------
Dim AppOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set AppOutLook = CreateObject("Outlook.Application")
Dim xref As Hyperlink
' logon
Dim xnamemail As String
xnamemail = "Default"
Call AppOutLook.GetNamespace("MAPI").Logon(Profile:=xnamemail)
Set MailOutLook = AppOutLook.CreateItem(olMailItem)
Dim SecurityManager As New AddInExpress.OutlookSecurityManager
SecurityManager.ConnectTo AppOutLook
SecurityManager.DisableOOMWarnings = True
Dim xhtmlstring As String
'the following logic will insert a <br/> whenever a cr/lf appears
For X = 1 To Len(Me.txt_body)
If mID(Me.txt_body, X, 1) = Chr(13) Then
xhtmlstring = xhtmlstring + "<br />"
Else
xhtmlstring = xhtmlstring + mID(Me.txt_body, X, 1)
End If
Next X
With MailOutLook
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = Me.txt_to
.Subject = Me.txt_subject
If Me.txt_attachment <> "" And _
Not IsNull(Me.txt_attachment) Then
.Attachments.Add "d:\storemanagement\emailpdf\" & _
pEmailAttachment
End If
.HTMLBody = "<body>" & xhtmlstring & "<br />" & _
"<br />" & _
"<br />" & _
"<br />" & _
mEmpFullName & "<br />" & _
"<b>Company Name<b/> " & "<br />" & _
"Phone Number: " & mPhoneNumber & "<br />" & _
IIf(mFaxNumber <> "", "Fax Number: " & mFaxNumber &
"<br />", "") & _
"Visit us at <a
href=http://www.companyname.com>www.companyname.com</a> " & "<br />" & _
"</body>"
'.Display True
.Send
End With
SecurityManager.DisableOOMWarnings = False
'let's close the form and go home
DoCmd.Close acForm, "frmMailOut"