Send Email via access

L

LeeTV

Hi,
Access 2007.
I'm wanting to send email to select records via a different account, than
the default, via outlook.
i'm able to send the emails now, but it defaults to the current email
account (which is personal).
I could create a new windows account, set up a new outlook and run the DB
from this login, but that defeats the purpose of what i want to do.
Some emails have to come from biling email address, some emails are for
course registrations, and other emails are for certification emailing.. to
create all these different windows accounts would be quite a process.

in short: how do i send email via an account in outlook? (I think it has
something to do with ADODB and not the current DOA that i am using).
Any help will be much appreciated.
thanks
lee
 
D

Douglas J. Steele

Check the Access EMail FAQ that Tony Toews has at
http://www.granite.ab.ca/access/email.htm

For what it's worth, it's doubtful it has anything to do with ADO vs. DAO.
Those are methods of accessing data, not methods for sending e-mail. Not
only that, but there's no reason not to use DAO with Access 2007.
 
T

Tony Toews [MVP]

LeeTV said:
I'm wanting to send email to select records via a different account, than
the default, via outlook.

olItem.SentOnBehalfOfName = "(e-mail address removed)"

If you're running on Exchange you might need that account to allow
your Outlook account permission to do so. Or something weird like
that.

Tony
 
L

LeeTV

thanks for your reply... i was wondering
where would i put the line of code. I tried placing at the top of the
module, but it didnt work.
here is the code i'm using:
Public Sub SendOutLookMessage( _
strEmailAddress As String, _
strEmailCCAddress As String, _
strEmailBccAddress As String, _
strSubject As String, _
strMessage As String, _
blnDisplayMessage As Boolean, _
Optional strAttachmentFullPath As String)




'* Copy this code and paste it into a new Access
'* Module. Click Tools > References and make sure
'* that "Microsoft Office Outlook x.0 Object Library"
'* is checked.
'*
'* This subroutine sends an e-mail message through
'* MS Outlook. If the "blnDisplayMessage" parm is
'* set to "False", the message is placed in the
'* Outlook Outbox. "True" displays the message, and
'* user will have to click "Send" to send it.
'*
'* Ex.:
'*
'* SendOutlookMessage _
'* "(e-mail address removed)", _
'* "(e-mail address removed)", _
'* "(e-mail address removed)", _
'* "Subject", _
'* "Body of Message", _
'* False, _
'* "C:\My Documents\MyAttachmentFile.txt"

Dim objApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim blnOutlookInitiallyOpen As Boolean
Dim strProcName As String




On Error Resume Next
strProcName = "SendOutlookMessage"

blnOutlookInitiallyOpen = True
Set objApp = GetObject(, "Outlook.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Outlook.Application")
'* Outlook wasn't open when this function started.
blnOutlookInitiallyOpen = False
End If
If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (1): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section

'Create the message
Set objOutlookMsg = objApp.CreateItem(olMailItem)
If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (2): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section

With objOutlookMsg
Set objOutlookRecipient = .Recipients.Add(strEmailAddress)
objOutlookRecipient.Type = olTo
If strEmailCCAddress = "" Then
Else
Set objOutlookRecipient = .Recipients.Add(strEmailCCAddress)
objOutlookRecipient.Type = olCC
End If
If strEmailBccAddress = "" Then
Else
Set objOutlookRecipient = .Recipients.Add(strEmailBccAddress)
objOutlookRecipient.Type = olBCC
End If
.Subject = strSubject
.Body = strMessage

'* Add attachments
If Not IsMissing(strAttachmentFullPath) Then
If Trim(strAttachmentFullPath) = "" Then
Else
Set objOutlookAttach = .Attachments.Add(strAttachmentFullPath)
If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (3): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section
End If
End If

If blnDisplayMessage Then
.Display
Else
'* Send message by putting it in the Outbox
.send
End If
End With

If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (99): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section

Exit_Section:
On Error Resume Next
If Not blnOutlookInitiallyOpen Then
objApp.Quit
End If
Set objApp = Nothing
Set objOutlookMsg = Nothing
Set objOutlookAttach = Nothing
Set objOutlookRecipient = Nothing
 
T

Tony Toews [MVP]

LeeTV said:
thanks for your reply... i was wondering
where would i put the line of code. I tried placing at the top of the
module, but it didnt work.

No, you'd have to put it after the below line.
With objOutlookMsg
.SentOnBehalfOfName = "(e-mail address removed)"
Set objOutlookRecipient = .Recipients.Add(strEmailAddress)

Note the period before the SentOnBehalfOfName

I think. I'm no Outlook code expert and I don't feel like copying
your code into a test Access MDB and testing it.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a free, convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top