Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- From: "MikeB" <bauerlie@xxxxxxxxxxx>
- Date: Sat, 1 Aug 2009 23:11:09 -0400
You can also use Windows API calls to capture the windows security dialog
automatically. I never tried it using VBA but have done it in Delphi.
Also, the security warning (IIRC) only comes up once per session, not once
per email, so if the OP can keep the OL object alive for the session, the
momentary click of the dialog shouldn't be too much of a bother.
"Peter Hibbs" <peter.hibbs@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:lfe975hp4h3d3oh0kbd9bl0dosqltnkckb@xxxxxxxxxx
To send an email from Access via MS Outlook and bypass the security
warnings you can use Outlook Redemption. This is a .dll file which is
installed and registered on the PC. Then you can use the code below to
send an email direct without any security warnings being shown. And it
is free.
To use Outlook Redemption first go to this site :-
http://www.dimastr.com/redemption/
and click on the Download Outlook Redemption link at the bottom of the
page. Then click on the Download Developer Version link to download
the zip file to your PC. Unzip the files and install the
Redemption.dll as instructed. The easiest option is to use the Install
program provided. You may find the Redemption.dll file is already
installed on your PC as some virus checkers use it.
Next create a new Module in your database and save it as
modOutlookCode (or whatever you want), copy and paste the code below
into the module and save it again.
'----------Redemption Code ----------------------
Option Compare Database
Option Explicit
Public Function SendMailAuto(vRecipients As String, _
vBCC As Variant, _
vSubject As Variant, _
vBody As Variant, _
vAttachments As Variant) As Boolean
'Send an automatic email via Microsoft Outlook
'Entry (vRecipients) = EMail address of recipient
' (vBCC) = EMail addresses of recipients
' (vSubject) = Subject text
' (vBody) = Email body text
' (vAttachments) = List of files to attach to e-mail
'Exit (SendMailAuto) = Returns True if no error reported
' (SendMailAuto) = Returns False if error reported
Dim vCount As Long, vArray() As String
Dim SafeItem As Object, oItem As Object
Dim objApp As Object, NS As Object
On Error GoTo ErrorCode
DoCmd.Hourglass True
'Create instance of Outlook Application
Set objApp = CreateObject("Outlook.Application")
Set NS = objApp.GetNamespace("MAPI")
NS.Logon
'Create an instance of Redemption.SafeMailItem
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = objApp.CreateItem(0)
SafeItem.Item = oItem
SafeItem.To = vRecipients
' If Not IsNull(vCC) Then SafeItem.CC = vCC '(not used here)
If Not IsNull(vBCC) Then SafeItem.BCC = vBCC
If Not IsNull(vSubject) Then SafeItem.Subject = vSubject
If Not IsNull(vBody) Then SafeItem.Body = vBody
'Add attachments (if any)
If Not IsNull(vAttachments) Then
vArray = Split(vAttachments, ",")
For vCount = 0 To UBound(vArray)
SafeItem.Attachments.Add (vArray(vCount))
Next
End If
'Send email and close
SafeItem.Send
Set SafeItem = Nothing
Set oItem = Nothing
Set NS = Nothing
Set objApp = Nothing
DoCmd.Hourglass False
SendMailAuto = True
Exit Function
ErrorCode:
DoCmd.Hourglass False
MsgBox Err.Description
SendMailAuto = False
End Function
To send an email just use the following code :-
If SendMailAuto(Me.txtTo, Me.txtBCC, Me.txtSubject, Me.txtBody,
Me.txtAttachments) = False Then
MsgBox "Some error occurred!", vbCritical + vbOKOnly, "EMail
Error"
End If
where the Text boxes (or variables) hold the recipient's email
address, BCC addresses, Subject and Body text.
If there is more than one email address in the To: and/or BCC: fields
then each address should be separated by a semi-colon. The
txtAttachments field holds the full pathname to any attachments to be
sent, i.e. something like "C:\Temp\Filename.txt". If there are more
than one file to attach then they should be separated by commas.
You do not need to set up a reference to Outlook in the VBA code, this
is particularly useful if the database is likely to be used on a
number of different PCs because, even though it is possible to have
different versions of Word, Excel, Access, etc installed on the same
PC, it is only possible to have one version of Outlook installed and
this could be a different version to the one used by the developer.
The email (and attachments) are temporarily stored in the Outlook
Drafts folder but are deleted automatically when you next use Outlook.
However, there is a 2GB limit on the total size of files stored in an
Outlook folder, if a large number of emails with large attachments
files is sent together, the 2GB limit may be exceeded in which case
Outlook will 'fall over' big time. Make sure this does not happen.
Also, if you are intending to send an email to a large number of
recipients, it is NOT a good idea to have a large number of email
addresses in the BCC: field. According to Outlook MVP, Sue Mosher, it
is likely that the recipient's ISP will flag the email as SPAM and bar
the email. As an alternative, she suggests sending one email at a time
which might take longer but would be more reliable. Also the sender's
ISP will set a limit on the number of email addresses that can be
entered in the BCC: field which probably varies with each ISP.
If you have any queries regarding the Redemption code then you should
post the question to the MS Outlook NG as Dmitry Streblechenko (the
author of Redemption) answers questions there.
HTH
Peter Hibbs.
On Sat, 1 Aug 2009 14:34:49 -0700 (PDT), robboll <robboll@xxxxxxxxxxx>
wrote:
I just realized that the referenced website is a vender advertising
their Add-Ins DUHHHHH
which makes the question more basic - - - how send an email withhout
the warning.
I have an Access application that when a new record is added, it needs
to send an email with info from a few fields from the entry. I don't
want the user to have to acknowledge the email from each new record.
I understand the security aspect of this, so the process should only
allow emails from the MS Access application and turn on the security
feature after each send.
I am seeing that there are a number of venders who are trying to sell
their solutions. I would go this route, but I know how quickly things
change with service packs and OS updates. There has to be a code
solution. Thanks for any suggestions!
RBollinger
.
- Follow-Ups:
- Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- From: Arvin Meyer [MVP]
- Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- References:
- Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- From: robboll
- Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- From: robboll
- Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- From: Peter Hibbs
- Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- Prev by Date: Re: Creating a table on a form
- Next by Date: Re: Creating a table on a form
- Previous by thread: Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- Next by thread: Re: Outlook email -- A program is trying to automatically send e-mail on your behalf . . .
- Index(es):
Relevant Pages
|