Results 1 to 11 of 11
  1. #1
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48

    Formatting E-mail Using Code

    I've started reading about sending e-mail from Access and was wondering if anyone has a good tutorial for it. Here's a piece of code I found but would like the ability to further format it. I used to know html but I'm not sure how to use it in the code. Has anyone seen anything where it gives you the code and then shows you what it actually will look like in an e-mail?

    Dim OL As Object, MailSendItem As Object
    Dim cust, prog, mess
    Set OL = CreateObject("Outlook.Application")
    Set MailSendItem = OL.CreateItem(olMailItem)


    With MailSendItem
    .Subject = "Routing:" & "Please complete the Sales Block and Close"
    .HTMLBody = .HTMLBody & "<body><font color=#ff0000>"
    .HTMLBody = .HTMLBody & "<p>Customer: " & cust & "</p>"
    .HTMLBody = .HTMLBody & "<p>Program: " & prog & "</p>"
    .HTMLBody = .HTMLBody & "<p>Subject: " & mess & "</p>"
    .HTMLBody = .HTMLBody & "<p>Please complete the First Sales Block and Close</p>"
    .HTMLBody = .HTMLBody & "</font></body>"
    .To = ""
    .CC = ""
    .Attachments.Add
    .Importance = 2 ' olImportanceHigh
    .Display
    .Send
    End With

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    You can do this with any kind of html program, I personally use Dreamweaver. There are probably lots of free ones out there. Or you could try the w3schools website http://www.w3schools.com/html/DEFAULT.asp where you can try it ou and it gices you tutorials.

    Once you've got your html sorted you just need to add it to the code, this can be done in one long string if you want.

  3. #3
    PianoMan64 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    29
    Quote Originally Posted by graviz View Post
    I've started reading about sending e-mail from Access and was wondering if anyone has a good tutorial for it. Here's a piece of code I found but would like the ability to further format it. I used to know html but I'm not sure how to use it in the code. Has anyone seen anything where it gives you the code and then shows you what it actually will look like in an e-mail?

    Dim OL As Object, MailSendItem As Object
    Dim cust, prog, mess
    Set OL = CreateObject("Outlook.Application")
    Set MailSendItem = OL.CreateItem(olMailItem)


    With MailSendItem
    .Subject = "Routing:" & "Please complete the Sales Block and Close"
    .HTMLBody = .HTMLBody & "<body><font color=#ff0000>"
    .HTMLBody = .HTMLBody & "<p>Customer: " & cust & "</p>"
    .HTMLBody = .HTMLBody & "<p>Program: " & prog & "</p>"
    .HTMLBody = .HTMLBody & "<p>Subject: " & mess & "</p>"
    .HTMLBody = .HTMLBody & "<p>Please complete the First Sales Block and Close</p>"
    .HTMLBody = .HTMLBody & "</font></body>"
    .To = ""
    .CC = ""
    .Attachments.Add
    .Importance = 2 ' olImportanceHigh
    .Display
    .Send
    End With

    Hey graviz:

    From the response you have gotten, are you looking for how to format the HTML for the email, or how to send HTML emails from MS Access?

    If you're wanting to send emails, and the user of the application has MS Outlook installed, here is a code example using a third party tool to bypass the internetal security issues within Outlook (Third Party tool is Outlook Redemption http://www.dimastr.com/redemption/) Developer Copy is free to download and use, Purchase price is $199 for unlimited users or projects.)

    Here is an example that I currently use to send Text based email.
    Code:
      Dim Application As New Outlook.Application
      Dim SafeItem As Redemption.SafeMailItem, oItem As Outlook.MailItem
      Dim Utils As Redemption.MAPIUtils
      Dim DC As Redemption.SafeCurrentUser, Tag As Variant
      Set Utils = New Redemption.MAPIUtils
      Set SafeItem = New Redemption.SafeMailItem
      Set oItem = Application.CreateItem(olMailItem)
      With SafeItem
        .Item = oItem
        Tag = SafeItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "From")
        Tag = Tag Or &H1E
        .Fields(Tag) = "Current User Name <Username@DomainName.com>"
        .Recipients.Add ("AdditionalUser@domainname.com")
        .Recipients.ResolveAll
        .Subject = "SUBJECT LINE GOES HERE"
        .Subject = .Subject 'Must have this in order for Redemption to have the subject line
        .Body = "Hey Team," & vbCrLf & vbCrLf & _
                "The Batch " & BatchNumber & " is ready for Processing. " & vbCrLf & vbCrLf & _
                "Files Imported: " & FileNumber & vbCrLf & _
                "Images Imported: " & Images
        .Save
        .Send
        End With
      Utils.DeliverNow
    Here is an example of how to send and HTML Email:

    Code:
    set Appt = Application.CreateItem(olMailItem)
    set sItem = CreateObject("Redemption.SafeMailItem")
    sItem.Item = Appt
    sItem.Recipients.Add "user@domain.com"
    sItem.Recipients.ResolveAll
    sItem.Subject = "test subject"
    sItem.HTMLBody = "<html><body><b>bold</b> text</body></html>"
     
    PR_InetMailOverrideFormat = &H59020003
    ENCODING_PREFERENCE = &H00020000
    BODY_ENCODING_TEXT_AND_HTML = &H00100000
    ENCODING_MIME = &H00040000
     
    PR_MSG_EDITOR_FORMAT = &H59090003
    EDITOR_FORMAT_PLAINTEXT = 1
    EDITOR_FORMAT_HTML = 2
     
    sItem.Fields(PR_InetMailOverrideFormat) = ENCODING_PREFERENCE or ENCODING_MIME or BODY_ENCODING_TEXT_AND_HTML
    sItem.Fields(PR_MSG_EDITOR_FORMAT) = EDITOR_FORMAT_HTML
    sItem.Send
    I hope that helps,

    Joe P.

  4. #4
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by PianoMan64 View Post
    Hey graviz:

    From the response you have gotten, are you looking for how to format the HTML for the email, or how to send HTML emails from MS Access?

    If you're wanting to send emails, and the user of the application has MS Outlook installed, here is a code example using a third party tool to bypass the internetal security issues within Outlook (Third Party tool is Outlook Redemption http://www.dimastr.com/redemption/) Developer Copy is free to download and use, Purchase price is $199 for unlimited users or projects.)

    Here is an example that I currently use to send Text based email.
    Code:
      Dim Application As New Outlook.Application
      Dim SafeItem As Redemption.SafeMailItem, oItem As Outlook.MailItem
      Dim Utils As Redemption.MAPIUtils
      Dim DC As Redemption.SafeCurrentUser, Tag As Variant
      Set Utils = New Redemption.MAPIUtils
      Set SafeItem = New Redemption.SafeMailItem
      Set oItem = Application.CreateItem(olMailItem)
      With SafeItem
        .Item = oItem
        Tag = SafeItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "From")
        Tag = Tag Or &H1E
        .Fields(Tag) = "Current User Name <Username@DomainName.com>"
        .Recipients.Add ("AdditionalUser@domainname.com")
        .Recipients.ResolveAll
        .Subject = "SUBJECT LINE GOES HERE"
        .Subject = .Subject 'Must have this in order for Redemption to have the subject line
        .Body = "Hey Team," & vbCrLf & vbCrLf & _
                "The Batch " & BatchNumber & " is ready for Processing. " & vbCrLf & vbCrLf & _
                "Files Imported: " & FileNumber & vbCrLf & _
                "Images Imported: " & Images
        .Save
        .Send
        End With
      Utils.DeliverNow
    Here is an example of how to send and HTML Email:

    Code:
    set Appt = Application.CreateItem(olMailItem)
    set sItem = CreateObject("Redemption.SafeMailItem")
    sItem.Item = Appt
    sItem.Recipients.Add "user@domain.com"
    sItem.Recipients.ResolveAll
    sItem.Subject = "test subject"
    sItem.HTMLBody = "<html><body><b>bold</b> text</body></html>"
     
    PR_InetMailOverrideFormat = &H59020003
    ENCODING_PREFERENCE = &H00020000
    BODY_ENCODING_TEXT_AND_HTML = &H00100000
    ENCODING_MIME = &H00040000
     
    PR_MSG_EDITOR_FORMAT = &H59090003
    EDITOR_FORMAT_PLAINTEXT = 1
    EDITOR_FORMAT_HTML = 2
     
    sItem.Fields(PR_InetMailOverrideFormat) = ENCODING_PREFERENCE or ENCODING_MIME or BODY_ENCODING_TEXT_AND_HTML
    sItem.Fields(PR_MSG_EDITOR_FORMAT) = EDITOR_FORMAT_HTML
    sItem.Send
    I hope that helps,

    Joe P.
    Thanks for the response. I'm basically looking for a good tut on sending e-mail from Access. I think I have the very basics dowm but I'm trying to learn more int to advanced ways of doing it.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's a site with a lot of good information.

  6. #6
    PianoMan64 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    29
    Quote Originally Posted by graviz View Post
    Thanks for the response. I'm basically looking for a good tut on sending e-mail from Access. I think I have the very basics dowm but I'm trying to learn more int to advanced ways of doing it.
    Hey Graviz:

    Then again I'm not sure what it is that you're trying to get out of a tutorial that I haven't already shown you how to do?

    Are you simply wanting to send emails from access or are you looking to do something more than that?

    let me know,

    Thanks,

    Joe P.

  7. #7
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by PianoMan64 View Post
    Hey Graviz:

    Then again I'm not sure what it is that you're trying to get out of a tutorial that I haven't already shown you how to do?

    Are you simply wanting to send emails from access or are you looking to do something more than that?

    let me know,

    Thanks,

    Joe P.
    An example of one thing I would like to do is:

    Copy a selection of cells from a certain Excel Spreadsheet (i.e. c:\report.xls B2:F:30

    Paste it in the e-mail as an Enhanced Metafile

  8. #8
    PianoMan64 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    29
    Quote Originally Posted by graviz View Post
    An example of one thing I would like to do is:

    Copy a selection of cells from a certain Excel Spreadsheet (i.e. c:\report.xls B2:F:30

    Paste it in the e-mail as an Enhanced Metafile
    You then simply include code that would access the area of the excel spreadsheet that you want, and paste with code into your body of the email.

    You just simply have to display the email first, and then paste the contents of the clipboard to the body of the email.

    using the docmd Option to print right from access to and email that get's sent with the specified parameters is not currently supported the way that you want it to work.

    You'll have to write custom code to get the functionality that you seek.

    If you do need help with this, I'd be more that happy to assist you.

    Hope that helps,

    Joe P.

  9. #9
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by PianoMan64 View Post
    You then simply include code that would access the area of the excel spreadsheet that you want, and paste with code into your body of the email.

    You just simply have to display the email first, and then paste the contents of the clipboard to the body of the email.

    using the docmd Option to print right from access to and email that get's sent with the specified parameters is not currently supported the way that you want it to work.

    You'll have to write custom code to get the functionality that you seek.

    If you do need help with this, I'd be more that happy to assist you.

    Hope that helps,

    Joe P.
    Do you have any code where you have done the same type of thing in the past that I could take a look with and figure out how it works.

  10. #10
    PianoMan64 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    29
    I don't but I could figure it out and send you what I find.

  11. #11
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by PianoMan64 View Post
    I don't but I could figure it out and send you what I find.
    Thanks! I really appreaciate it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-16-2009, 01:58 PM
  2. E-mail Reports
    By Mike Cooper in forum Reports
    Replies: 2
    Last Post: 08-04-2008, 12:58 AM
  3. Mail merge
    By grgerhard in forum Forms
    Replies: 0
    Last Post: 04-25-2006, 05:06 PM
  4. Mail Merge problem
    By kfergus in forum Programming
    Replies: 0
    Last Post: 04-24-2006, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums