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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Multiple Emails

Status
Not open for further replies.

murk

Technical User
Nov 26, 2002
16
US
I have just set up a database with company information and added each company's email address(es). Is there a way to send, say a letter, to multiple addresses through access and if so what are the exact steps in setting this up?

Thanks!

Jennifer
 
Here's what I use (some of the lines get split into two, so you'll have to fix that). This sends an email with a form attached.

'------------------------------------------------------------
' SendNotice
'
'------------------------------------------------------------
Function SendNotice()
On Error GoTo SendNotice_Err

' Sends a notice to the area managers that the report files have been generated.
DoCmd.SendObject acForm, "YourFormName", "User Name", "", "Mail Title", "Your Message"".", False, ""


SendNotice_Exit:
Exit Function

SendNotice_Err:
MsgBox Error$
Resume SendNotice_Exit

End Function
 
Jenifer

They way to code this depends on the mail program you're using. Submit a post stating whether you're using Outlook or Lotus Notes etc.

The example from GDGarth is fine for attaching a report but if you'd like to attach a Word document or any other file type there are much better methods. I have plenty of sample code for this and will post it for you once I know which mail program you're using.

Regards

Damien
 
We use Outlook express.

Thanks,
Jennifer
 
Damien

I use Lotus Notes to send mail. Can you tell me how to read the Mail.ID / password of the user for the Notes session in order to send the message or mail.:->

Regards
 
Damien,

Thsi is a question that comes up quite frequently (I know I will be looking to do some similar emailing of merged Word documents in the next few months). If you have the time to put your sample code into an FAQ, you will probably make a lot of people very happy.

Thanks,
Clive
 
Actually, let me clarify the issue. What I'm trying to accomplish is pulling mulitple email addresses from my access database and firing my email client (which is Outlook 2000) and populating the "to" field with those email addresses. Currently I am able to use the "mailto:" in the hyperlink I have established in access to start my email client and populate the "to" field but it only works for one address at a time. I hope this clarifies things and someone has an answer.

Thanks!

Jennifer
 
Hi all

I'm at work today but will put together an answer to all your questions (I hope!) after work tonight - I can help with both Outlook and Notes.

Regards

Damien
 
Hi again

Jennifer, before we reinvent the wheel have a look at this FAQ faq702-2921 it covers just about everything to do with email via Outlook. If you have any trouble interpreting what you find and need some code written specifically to your requirements then post again and I'll happily have a look.

Lotus Notes users, paste this lot into your code. It works like a treat, and even with a large number of recipients you'll probably be very surprised how quickly it executes. I've included a few options you may prefer to delete or comment out - like saving the email in your sent folder, passing the Notes password etc. (you don't need to initialise the password if Notes is already running).

Note: You must add a reference to Lotus Notes Automation Classes (notes32.tlb) from the Tools > References menu

Regards

Damien


Code:
Dim notesdb As Object                   ' notes Database
Dim notesdoc As Object                  ' notes email document
Dim notesrtf As Object                  ' notes email body
Dim notessession As Object              ' notes session
Dim names As Variant                    ' will become an array to hold all
                                        ' recipient addresses
Dim subj As String                      ' the email subject
Dim body_text As String                 ' the email body text
Dim file_path As String                 ' the attachment DOS path


ReDim names(name_count)                 ' name_count is a count of all
                                        ' recipients.this code doesn't show
                                        ' how to perform this count
                                        ' as there are so many ways to
                                        ' collect the names such as the
                                        ' selected items in a combo-box,
                                        ' a recordset from a query, a
                                        ' collection of text boxes etc.
                                        ' it should be easy to adapt
                                        ' your code to suit.
                                        
' at this point you need to convert your list of recipients into an array.
' how to do this is beyond the scope of this code as the source of names is
' so variable (as mentioned above).
' In structured English your code should look something like this:
'           For Each email address In recipient list
'               add email address to array
'              Next
' however you do it, add the email addresses to the "names" array

subj = "This email is for you!"                         ' get subject
body_text = "This text goes into the body of the email" ' get body text
file_path = "C:\filename.txt"                           ' get attachment path

Set notessession = CreateObject("Notes.Notessession")   ' start notes
Set notesdb = notessession.GetDatabase("", "")          ' set notesdb to
                                                        ' database not yet named
Call notesdb.OPENMAIL                                   ' assigns notesdb to
                                                        ' current user's mail
                                                        ' database and opens it

Set notesdoc = notesdb.CreateDocument                   ' create new email
Call notesdoc.replaceitemvalue("Sendto", names)         ' set receipt address
Call notesdoc.replaceitemvalue("Subject", subj)         ' set subject
Set notesrtf = notesdoc.CreateRichTextItem("body")      ' create body section
Call notesrtf.AddNewLine(1)                             ' insert 1 carriage
                                                        ' return
Call notesrtf.AppendText(body_text)                     ' append body text
Call notesrtf.AddNewLine(4)                             ' insert 4 carriage
                                                        ' returns
Call notesrtf.EmbedObject(1454, "", file_path)          ' attach file
notesrtf.SaveMessageOnSend = True                       ' save message in Sent
                                                        ' folder
Call notesdoc.Send(False)                               ' send email
Set notessession = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top