Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003

    Unhappy Unanswered: Send e-mails with VBA Automation

    I am trying to send e-mails with VBA automation.

    The automation server is MS Outlook, and the client is MS Access.

    I wanted to format the message body of the e-mail,

    e.g. to make some words BOLD, and some ITALIC.

    But I don't know how to do this, I can't find any property or method in

    the Outlook Object model for doing this. I can find ONLY 1 property

    called BODY for setting the message content, and that's it.


  2. #2
    Join Date
    Nov 2002
    Sacramento, CA

    Re: Send e-mails with VBA Automation

    try this: (you will need to edit srtHTML for your own use)

    Function SoftwareChange_Emailer()

    Dim iMsg
    Dim iConf
    Dim Flds
    Dim strHTML

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    ' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

    With Flds
    .Item("") = 2
    .Item("") = "your smtp server here"
    .Item("") = 10
    End With

    ' Build HTML for message body.
    strHTML = "<HTML><HEAD>"
    strHTML = strHTML & "<b>1 or more new software installs may have happened. Please review the</br>"
    strHTML = strHTML & "information below and correct the license counts accordingly. </br></HEAD>"
    strHTML = strHTML & "</br><BODY>"
    strHTML = strHTML & "<FONT Face=Arial Color=#ff0000 Size=5>Job #: 123456</FONT></br>"
    strHTML = strHTML & "<FONT Size=3>For: <FONT Size=2></B>a name here</br>"
    strHTML = strHTML & "<FONT Size=3><B>Description: </B><FONT Size=2>description of work to be done</FONT></br>"
    strHTML = strHTML & "</BODY></HTML>"

    ' Apply the settings to the message.
    With iMsg
    Set .Configuration = iConf
    .To = "email name here"
    .From = "another name here"
    .subject = "type a subject here"
    .HTMLBody = strHTML
    End With

    ' Clean up variables.
    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing

    End Function

    You can also try using: (note the templete on the end)
    DoCmd.SendObject acForm, "form name", "HTML(*.html)", MsgTo, MsgCC, MsgBCC, EmailSubject, EmailBody, True, "Templete.html"
    Last edited by dragracer; 07-21-03 at 11:13.
    Make the money, don't let the money make you.

  3. #3
    Join Date
    Jul 2003

    Red face Can I do it with Outlook Objects ?

    Can I do that with MS Outlook object model instead of using CDO objects ??

    I am familiar with Outlook , but not with CDO objects.

  4. #4
    Join Date
    Nov 2002
    Sacramento, CA

    Thumbs up

    Give this a try. just found this my self........think I'll need to recode a few things (note the .HTMLBody, instead of just .Body, was the only change that was needed to get the email format to HTML)

    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim strHTML As String

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
    ' Set the "From" field
    objOutlookMsg.SentOnBehalfOfName = "email names From"

    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("email names To")
    objOutlookRecip.Type = olTo

    ' Add the CC recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("email names CC")
    objOutlookRecip.Type = olCC

    ' Set the Subject, Body, and Importance of the message.
    .Importance = olImportanceHigh 'High importance
    .Subject = "Heres your subject"

    '.Body sets the email format to plain text, .HTMLBody changes it to HTML format
    strHTML = "<b>this might work</b><br>so could this"
    .HTMLBody = strHTML

    ' Add attachments to the message.
    If Not IsMissing(AttachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    End If

    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients


    End With
    GoTo fSendMessage_End

    'variable clean-up
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    Set objOutlookRecip = Nothing
    Set objOutlookAttach = Nothing
    End Function
    Last edited by dragracer; 07-22-03 at 10:34.
    Make the money, don't let the money make you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts