PDA

View Full Version : Send Email Attachment from within Access



Hatman
07-27-2005, 02:06 PM
Is there any way to send an email with an attachment from within my code. I don't want to send an access object. I want to send a file that is saved on my system. is this possible?

Thank you

mark007
07-27-2005, 06:16 PM
Sure, are you wanting to send it through MS Outlook or another program?

Hatman
07-27-2005, 07:17 PM
I've assumed I'd have to send it with Outlook so that would be fine.

Hatman
07-27-2005, 07:25 PM
I've assumed I'd have to send it with Outlook so that would be fine.

xCav8r
07-27-2005, 07:42 PM
I've never tried automating outlook, but if you're talking about an attachment that's an office doc, then you can probably use send mail from that app and control it from Access. Alternatively, you might find this helpful...http://support.microsoft.com/default.aspx?scid=kb;en-us;161088

mark007
07-28-2005, 02:23 AM
To automate Outlook you can use the following:



Sub SendMail()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem

'get application
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then Set olApp = New Outlook.Application
On Error GoTo 0

Set olMail = olApp.CreateItem(olMailItem)
With olMail
.Subject = "My email with attachment"
.Recipients.Add "name@host.com"
.Attachments.Add "c:\test.txt"
.Body = "Here is an email"
.Display 'This will display the message for you to check and send yourself
'.Send ' This will send the message straight away
End With


End Sub


Note that for versiosn of Outlook above 2000 you will get security warnings that a program is trying to control it which can make it awkward to use.

:)

xCav8r
07-29-2005, 10:23 PM
Mark, if that's not already a KB entry, you should submit it.