AT_Mail.bas 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Option Compare Database
  2. Option Explicit
  3. ' ** Access Toolbox Module **
  4. ' on 2017-02-28,
  5. ' @author: Olivier Massot
  6. ' V 1.0
  7. ' Send mails
  8. ' ! Requires Microsoft Outlook XX.X library
  9. Public Sub send_mail(ByVal subject As String, _
  10. ByVal content As String, _
  11. Optional recipient As String, _
  12. Optional auto_send As Boolean = False, _
  13. Optional attachment As String = "", _
  14. Optional signature As Boolean = False)
  15. Dim olApp As Outlook.Application
  16. Dim objMail As Outlook.MailItem
  17. Dim oAccount As Outlook.Account
  18. Dim olExplorer As Outlook.Explorer
  19. Set olApp = GetObject("", "Outlook.Application")
  20. Dim mpf As Outlook.MAPIFolder
  21. Dim is_html As Boolean
  22. is_html = (Left(content, 6) = "<html>")
  23. Set objMail = olApp.CreateItem(olMailItem)
  24. objMail.subject = subject
  25. If is_html = True Then
  26. If signature = True Then
  27. objMail.display
  28. objMail.HTMLBody = content & vbNewLine & objMail.HTMLBody
  29. If auto_send Then objMail.Close olDiscard
  30. Else
  31. objMail.HTMLBody = content
  32. If Not auto_send Then objMail.display
  33. End If
  34. objMail.BodyFormat = olFormatHTML
  35. Else
  36. objMail.Body = content
  37. objMail.BodyFormat = olFormatRichText
  38. If Not auto_send Then objMail.display
  39. End If
  40. If Len(attachment) > 0 Then
  41. objMail.Attachments.Add attachment, olByValue, 1
  42. End If
  43. objMail.To = recipient
  44. 'objMail.Cc = ""
  45. 'objMail.BCC= ""
  46. If auto_send Then objMail.send
  47. Set olApp = Nothing
  48. Set objMail = Nothing
  49. End Sub
  50. Public Function current_account()
  51. Dim olApp As Outlook.Application
  52. Set olApp = GetObject("", "Outlook.Application")
  53. current_account = olApp.Session.Accounts(1).SmtpAddress
  54. End Function