Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Programmatically sending email from Access (http://www.outlookbanter.com/outlook-vba/19797-programmatically-sending-email-access.html)

scariharry July 5th 06 05:08 PM

Programmatically sending email from Access
 
Well with Sue's help I found a solution to the security dialogs that pop up
when I tried to send email out of Access to Outlook.


Two prong approach using both Access and Outlook in VBA

In Access:

Option Compare Database
Option Explicit
Public Sub SendMessage1()

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAtt As Outlook.Attachment
Dim strBody As String

Set objOutlook = New Outlook.Application 'Create the Outlook session
Set objOutlookMsg = objOutlook.CreateItem(olMailItem) 'Create message

With objOutlookMsg
.To = "Dist List" 'Send To:
.CC = "" 'CC:
.Subject = "This is a Test..... this is only a test -+agmm" 'Subject:
'Msgtxt: Body is set below attachment line....
strBody = "Like I said, it's just a test."
strBody = strBody & vbCrLf & "Still testing"
strBody = strBody & vbCrLf & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'Importance
'Attachments
Set objOutlookAtt = .Attachments.Add("[path]")
strBody = strBody & vbCrLf & "That is an attachment" & vbCrLf & vbCrLf
.Body = strBody
.Save
End With
End Sub


In Outlook:
Public WithEvents sndDraft As Outlook.Items


Public Sub Application_Startup()

Set sndDraft = Outlook.Session.GetDefaultFolder(olFolderDrafts).I tems

End Sub


Private Sub sndDraft_ItemAdd(ByVal Item As Object)

Dim objSubT As String
objSubT = Right(Item.Subject, 6)

If TypeName(Item) = "MailItem" Then
If objSubT = "-+agmm" Then

Dim objSub As String
Dim objSubF As String
Dim subLen As Integer
objSub = Item.Subject
subLen = Len(objSub)
objSubF = Left(objSub, (subLen - 6))

Item.Subject = objSubF
Item.Send

End If
End If

End Sub

This works with not a single security blurb.....

Thanks Sue


All times are GMT +1. The time now is 03:48 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com