Use HTML tags in e-mail Message

E

Eka1618

Hello,

I would like to format the text that is placed into my e-mails that are ent
out through the DB. I am having a hard time trying to find out information
that will help me on this issue. I do not know how to use HTML tags in VB. I
found a forums where someone suggested using: "" & "some text" & ""

This does not work. I know HTML, just not how to use it in VB. Below is an
example of the format I currently use to send an e-mail message. If anyone
has any suggestions please let me know. Thank you!

~Erica~


Public Sub SendRequest(frm As Form)
Dim emName, emName2 As String, varItem As Variant
Dim emailBody As String
Dim emailSubject As String

emailSubject = "Product Test Request (Tech. Team Leader next action)"

On Error GoTo btnSend_Click_error


frm.REQUEST_NO.SetFocus
emailBody = "Hello, " & vbCrLf & vbCrLf & _
"A product test request has been issued for Request Number: " &
frm.REQUEST_NO.Text & "." & _
vbCrLf & vbCrLf & "Please log into the Product Engineering Test Database
to review this request to continue the process, Thank You!"

For Each varItem In frm!lboRequestee.ItemsSelected
emName = emName & Chr(34) & frm!lboRequestee.Column(2, varItem) &
Chr(34) & ","
Next varItem

For Each varItem In frm!lboRequestor.ItemsSelected
emName2 = emName2 & Chr(34) & frm!lboRequestor.Column(2, varItem) &
Chr(34) & ","
Next varItem

'remove the extra comma at the end
'add the requestor to the e-mail list recipients
emName2 = Left$(emName2, Len(emName2) - 1)
emName = Left$(emName, Len(emName) - 1)

'send message
frm.Visible = False
DoCmd.SendObject acSendNoObject, , , emName, emName2, , emailSubject,
emailBody, True, False

btnSend_Click_error:
If Err.Number = 2501 Then
MsgBox "You just canceled the e-mail", vbCritical, "Alert"
End If
End Sub
 
P

pietlinden

Hello,

I would like to format the text that is placed into my e-mails that are ent
out through the DB. I am having a hard time trying to find out information
that will help me on this issue. I do not know how to use HTML tags in VB.. I
found a forums where someone suggested using: "" & "some text" & ""

This does not work. I know HTML, just not how to use it in VB. Below is an
example of the format I currently use to send an e-mail message. If anyone
has any suggestions please let me know. Thank you!

~Erica~

Public Sub SendRequest(frm As Form)
    Dim emName, emName2  As String, varItem As Variant
    Dim emailBody As String
    Dim emailSubject As String

    emailSubject = "Product Test Request (Tech. Team Leader next action)"

    On Error GoTo btnSend_Click_error

    frm.REQUEST_NO.SetFocus
    emailBody = "Hello, " & vbCrLf & vbCrLf & _
    "A product test request has been issued for  Request Number: "  &
frm.REQUEST_NO.Text &  "." & _
    vbCrLf & vbCrLf & "Please log into the Product Engineering Test Database
to review this request to continue the process, Thank You!"

    For Each varItem In frm!lboRequestee.ItemsSelected
    emName = emName & Chr(34) & frm!lboRequestee.Column(2, varItem)&
Chr(34) & ","
    Next varItem

    For Each varItem In frm!lboRequestor.ItemsSelected
    emName2 = emName2 & Chr(34) & frm!lboRequestor.Column(2, varItem) &
Chr(34) & ","
    Next varItem

    'remove the extra comma at the end
    'add the requestor to the e-mail list recipients
    emName2 = Left$(emName2, Len(emName2) - 1)
    emName = Left$(emName, Len(emName) - 1)

    'send message
    frm.Visible = False
    DoCmd.SendObject acSendNoObject, , , emName, emName2, , emailSubject,
emailBody, True, False

btnSend_Click_error:
    If Err.Number = 2501 Then
    MsgBox "You just canceled the e-mail", vbCritical, "Alert"
    End If
End Sub

Wait. You know HTML and you haven't figured out that it's <b>bolded
text</b>?
 
E

Eka1618

I know that <b> means bold (I know HTML).... I do not know how to write HTML
in VB for Access... It's not working...

I've seen some examples where you use: olApp.CreateItem(olMailItem)
and use it's properties ... but I do not think that it will work in my
situation with how I generate my e-mails.

I just want to know how I can get the HTML to edit the Text that goes into
the message.... when i try to do it, It displays the tage in the message and
they obviously are not working.

~Erica~

Hello,

I would like to format the text that is placed into my e-mails that are ent
out through the DB. I am having a hard time trying to find out information
that will help me on this issue. I do not know how to use HTML tags in VB.. I
found a forums where someone suggested using: "" & "some text" & ""

This does not work. I know HTML, just not how to use it in VB. Below is an
example of the format I currently use to send an e-mail message. If anyone
has any suggestions please let me know. Thank you!

~Erica~

Public Sub SendRequest(frm As Form)
Dim emName, emName2 As String, varItem As Variant
Dim emailBody As String
Dim emailSubject As String

emailSubject = "Product Test Request (Tech. Team Leader next action)"

On Error GoTo btnSend_Click_error

frm.REQUEST_NO.SetFocus
emailBody = "Hello, " & vbCrLf & vbCrLf & _
"A product test request has been issued for Request Number: " &
frm.REQUEST_NO.Text & "." & _
vbCrLf & vbCrLf & "Please log into the Product Engineering Test Database
to review this request to continue the process, Thank You!"

For Each varItem In frm!lboRequestee.ItemsSelected
emName = emName & Chr(34) & frm!lboRequestee.Column(2, varItem) &
Chr(34) & ","
Next varItem

For Each varItem In frm!lboRequestor.ItemsSelected
emName2 = emName2 & Chr(34) & frm!lboRequestor.Column(2, varItem) &
Chr(34) & ","
Next varItem

'remove the extra comma at the end
'add the requestor to the e-mail list recipients
emName2 = Left$(emName2, Len(emName2) - 1)
emName = Left$(emName, Len(emName) - 1)

'send message
frm.Visible = False
DoCmd.SendObject acSendNoObject, , , emName, emName2, , emailSubject,
emailBody, True, False

btnSend_Click_error:
If Err.Number = 2501 Then
MsgBox "You just canceled the e-mail", vbCritical, "Alert"
End If
End Sub

Wait. You know HTML and you haven't figured out that it's <b>bolded
text</b>?
 
E

Eka1618

no one has any suggestions? There must be a way...

Eka1618 said:
I know that <b> means bold (I know HTML).... I do not know how to write HTML
in VB for Access... It's not working...

I've seen some examples where you use: olApp.CreateItem(olMailItem)
and use it's properties ... but I do not think that it will work in my
situation with how I generate my e-mails.

I just want to know how I can get the HTML to edit the Text that goes into
the message.... when i try to do it, It displays the tage in the message and
they obviously are not working.

~Erica~

Hello,

I would like to format the text that is placed into my e-mails that are ent
out through the DB. I am having a hard time trying to find out information
that will help me on this issue. I do not know how to use HTML tags in VB.. I
found a forums where someone suggested using: "" & "some text" & ""

This does not work. I know HTML, just not how to use it in VB. Below is an
example of the format I currently use to send an e-mail message. If anyone
has any suggestions please let me know. Thank you!

~Erica~

Public Sub SendRequest(frm As Form)
Dim emName, emName2 As String, varItem As Variant
Dim emailBody As String
Dim emailSubject As String

emailSubject = "Product Test Request (Tech. Team Leader next action)"

On Error GoTo btnSend_Click_error

frm.REQUEST_NO.SetFocus
emailBody = "Hello, " & vbCrLf & vbCrLf & _
"A product test request has been issued for Request Number: " &
frm.REQUEST_NO.Text & "." & _
vbCrLf & vbCrLf & "Please log into the Product Engineering Test Database
to review this request to continue the process, Thank You!"

For Each varItem In frm!lboRequestee.ItemsSelected
emName = emName & Chr(34) & frm!lboRequestee.Column(2, varItem) &
Chr(34) & ","
Next varItem

For Each varItem In frm!lboRequestor.ItemsSelected
emName2 = emName2 & Chr(34) & frm!lboRequestor.Column(2, varItem) &
Chr(34) & ","
Next varItem

'remove the extra comma at the end
'add the requestor to the e-mail list recipients
emName2 = Left$(emName2, Len(emName2) - 1)
emName = Left$(emName, Len(emName) - 1)

'send message
frm.Visible = False
DoCmd.SendObject acSendNoObject, , , emName, emName2, , emailSubject,
emailBody, True, False

btnSend_Click_error:
If Err.Number = 2501 Then
MsgBox "You just canceled the e-mail", vbCritical, "Alert"
End If
End Sub

Wait. You know HTML and you haven't figured out that it's <b>bolded
text</b>?
 
R

Rick Brandt

Eka1618 said:
no one has any suggestions? There must be a way...

Not with SendObject. You need to automate an external messaging library
like Outlook or CDO to send HTML formatted Emails.
 
D

dch3

But if you're using Outlook to create and send the mail message, its a matter
of using the .HTMLBody property as opposed to the .Body property. I can't
discuss all of the finer nuances between the two, but I do seem to recall
that if you use .HTMLBody you should also set the .Body property to allow for
situations where the user is reading the message in a situation where the
HTML isn't rendered. Checkout the OUTLOOK discussion group for more
specifics.
 
D

dch3

And let me clarify me last post as I thought you were using Outlook via VBA
and not SendObject try this to get you going...

sub createMailItem()

Dim objOutlook As Outlook.Application
Dim newMail As Object

Set objOutlook = CreateObject("Outlook.application")
Set newMail = objOutlook.CreateItem(olMailItem)

newMail.Body = "The Office Ribbon sucks!"
newMail.To = "(e-mail address removed)"
Set newMailAttachments = newMail.Attachments
newMailAttachments.Add file1, olByValue, 1
newMail.Subject = "CONFIRMATION: " & strDescription & " (" & Now() &
")"
newMail.Display

end sub
 
E

Eka1618

Thanks dch3,

I have come up with the following sub routine that is eliminating the 'On
Behalf' error that you get from outlook is you try to send an e-mail without
editing it. I believe i can use .HTMLbody here, so I am going to try putting
HTML tags in this section to see what happens. Thanks for the help!

Public Sub SendEMail()
'Send an e-mail using the outlook application object...
'version 1.0
'1.0: Initial version.

Dim outOutlookInstance As Outlook.Application
Dim maiMessage As MailItem
Dim lngCounter As Long
Dim strArray() As String
Dim emName As String, varItem As Variant
Dim emailBody As String
Dim emailSubject As String

On Error GoTo SendEMail_Error

'Create the Outlook instance...
Set outOutlookInstance = CreateObject("Outlook.Application")

emailSubject = "Test Request Accepted (Requestor next action required)"

Me.REQUEST_NO.SetFocus

emailBody = "Hello," & vbCrLf & vbCrLf & _
"The product test request for Request Number: " & REQUEST_NO.Text & _
" has been Accepted by the Tech Team Leader." & vbCrLf & vbCrLf & _
"To review the status of this product test request, " & _
"Please log into the Product Engineering Database, and view the status
on the Test Queue Screen." & vbCrLf & vbCrLf & _
"Thank You!"

'Need to capture the requestee's e-mail address and assign it to the
..SentOnBehalfOfName

'Create the mail message...
Set maiMessage = outOutlookInstance.CreateItem(olMailItem)
With maiMessage
.To = CurrentDb.Properties("RequestorEmail")
.SentOnBehalfOfName = CurrentDb.Properties("RequesteeEmail")
.subject = emailSubject
.body = emailBody

'Send the message...
.Send

End With

'Clear the objects...
Set maiMessage = Nothing
Set outOutlookInstance = Nothing


SendEMail_Error:
If Err.Number <> 0 Then
MsgBox Err.Number & ": " & Err.description, vbCritical, "SendEMail"
End If

End Sub
 
D

dch3

The two lines that set the .To and .SentOnBehalfOfName have me a bit leary,
but I don't know your database like you do. I would suggest putting in an
check to abort the .Send if something happens were the database properties
return a zero-length string.

Also, if you're dealing with something that must be done by a set date and
time, and you're working with users within your own organization, you may
want to consider sending it as a TaskRequest as opposed to a regular
MailItem. That way you can track the status of it via Outlook.
 
D

dch3

Not certain if my last post actually posted, but...

You may want to include a If...Then in the event that the .To and
..SendOnBehalf aren't populated because the DB properties are zero length
string. I'm just paranoid.

Also, if you're working with internal teams, you could send them a
TaskRequest which opens up a world of possibilities in terms of tracking if
the task has been completed.

Finally, I haven't worked with ASP.NET, just good ol' ASP, but you could
create a page that queries your database and provides the status information
via a webpage. In ASP Classic, it's just a matter of creating a connection to
the database and looping through the records. *VERY* similar to doing the
same thing directly in Access.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top