Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to send Outlook emails from Access 7

Status
Not open for further replies.

gazolba

Programmer
Dec 4, 2001
167
0
0
US
Where can I find the code to send Outlook emails from Access. I need to be able to set the 'importance flag' and need to be able to control the 'from' and 'to' emails. I need an example that emails to multiple addresses. Have not been able to find this anywhere. Hope someone can help.
MS Access help is useless. I'm using Access 2000.
 
I would look into the using the MAPI controls.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi,
This is my clickedEvent code in one of my sample applications. The user selects the "importance" from a listbox (lstImportance), the subject line (txtSubjectLine) and the message (txtMessage). Be sure to set the references to include Microsoft Outlook #.0 Object Library (9.0 is Access 2000).

Private Sub cmdSendEmail_Click()
Dim intImportance As Integer

Select Case lstImportance
Case "High"
intImportance = 2
Case "Normal"
intImportance = 1
Case "Low"
intImportance = 0
End Select

Dim myApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Set myItem = myApp.CreateItem(olMailItem)
With myItem
.Importance = intImportance
.To = "rsmith@cta.org"
.Subject = txtSubjectLine.Value
.ReadReceiptRequested = False
.Body = txtMessage.Value
End With
myItem.Send

End Sub



HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Thanks, thats great but I need an example that sends emails to multiple addresses, do I just connect them with semi-colons?
 
Hi,
You can do that if you have specific email addresses. BUT, if you want to send to a set of individuals that the user selects (perhaps from a multi-select listbox), then you would loop through the recordset. I wrote an FAQ on how to use the ItemsSelected property of a listbox in a report (faq703-2657} - see the section called "Multiple Selection Example". That particular code is building a string to be sent to a report as criteria, but your solution will loop through the records and include the "with myItem" code (through the myItem.Send statement). Presumably, your listbox will contain email addresses (hint: name in first column, but email address in 2nd-----AND, the bound column for the listbox will be the one with the email address).

HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Specifically I need to know how to include multiple emails in the MYITEM.TO = assignment

I know all about listboxes and recordsets.
My emails are actually in a collection and I loop thru the collection.
 
Hi,
Simply place all the email addresses in a string, and separate each entry with the semicolon (;). If you look carefully at the code in my "filter" FAQ, you will see that it appends " OR " to the end of the string each time a new item was found while looping. Well, when it gets done, you will see the code that subtracts out the last " OR ".


HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
Thanks. I found a piece of code that does the 'to' addresses in a different way it uses a property called 'recipients'. How do I get an email address in the 'CC' list?
 
How do I get an email address in the 'CC' list?
myItem.CC = "user1@domain1.com;user2@domain2.com"
where myItem is the MailItem object you want to send.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi,
There are a bunch of properties of the MailItem object (which we declared as "MyItem". These properties include:
attachments
BCC
CC
DeferredDeliveryTime
Importance
Recipients

Of course, you can look these up yourself by going into the code and typing "myItem." (without the quote marks). Access's autofill will show a list of all the properties and methods available to that particular object.


HTH, [pc2]
Randy Smith, MCP
rsmith@cta.org
California Teachers Association
 
does anyone know how to include images in the body of an email? i've been researching everywhere, and i can't seemto figure out how (if its even possible?)
 
You have to set .BodyFormat = olFormatHTML and play with the .HTMLBody property (and perhaps discover the object model guard)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV - you were right about the .HTMLbody property, i was about to give up on it completely. have a star :)
 
This is great info! Have looked all over the place for something like this - am learning to always check Tek-Tips first!

Quick additional question regarding the sending of HTML formatted emails using the MailItem object:

When the user tries to send the email, Microsoft Outlook generates a window stating:

'A program is trying to automatically send email on your behalf. Do you want to allow this? If this is unexpected it may be a virus and you should choose "No".'

I would really like to preview the email before sending it and would rather work around this additional security if possible.

Thanks for any help!
Michelle
 
Hi Michelle!

I am not sure about the previewing but the warning generated by Outlook is part of the install done by your IT group. It can be undone but most security people wouldn't recommend it.



Jeff Bridgham
bridgham@purdue.edu
 
The Email warning was put in place to help stop the slew of Outlook propagated viruses that sprang up over the past couple years or so. I seem to remember reading that you can write a COM add in for Outlook and register that with your mail server as a "trusted" add in, but I am a little fuzzy on the whole process. I can look up the links if needed. There are also some third party programs around that will send a click to the window, you can do the same thing via SENDKEYS IIRC.

That being said, it is an integrated part of Windows Security now and while it makes it harder to work with Outlook it still is a small price to pay for better security.
 
I'm grateful for your help - as well as for any added security that helps stop these wild viruses - and I'm sure I could live with the pop-up, if I could only preview the email before sending it. That gives the user a reason to stop and look, and then, when they press 'send', they can deal with the security as need be. I know that I can use the SendObject command and have it open in an editable format, but I was hoping to have my HTML and eat it too...

Right now I am using .send, but I have tried .save as well, which only saves the email in the draft box. Any thoughts on how to preview or open a saved file?
 
Try .Display instead of .Send

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top