dbTalk Databases Forums  

Email to more than 1 recipient

comp.databases.ms-access comp.databases.ms-access


Discuss Email to more than 1 recipient in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default Email to more than 1 recipient - 06-03-2011 , 07:59 AM






I use the following to send an email to various people.
When there is a single MailTo name (e.g. Fred Smith) it works fine
If I want to send it to Fred Smith and John Jones I have tried "Fred Smith;
John Jones", but it only gets sent to the first person. John Jones in the
Outlook address book twice, and I get asked which one I want to use, so
Outlook is recognising both names. Do I need to do something with
Outlook.Recipients

Thanks

Phil

'Create a new mailitem and bring Outlook window to front
Set oItem = oOutlookApp.CreateItem(OLMailItem)
oItem.Display
FnSetForegroundWindow ("*outlook*")

With oItem
'Set the recipient for the new email
.To = MailTo
'Set the recipient for a copy
.CC = ""
'Set the subject
.Subject = Subject
ReadReceiptRequested equested = MsgRead ' Flag for message read
'The content of the document is used as the body for the email
If IsRtf = True Then ' Rtf message
.BodyFormat = olFormatHTML
.Body = ""
.HTMLBody = RTFText
Else ' Plain text
.HTMLBody = BodyText
End If

'Attachment is the attachment
If AttachmentsFound = True Then
For For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then
If Attach(j) > "" Then
Set olAttachment = .Attachments.Add(Attach(j))
End If
End If
Next j
End If
Call Call apWait(2, False) ' Time for the email to display before sending
.Send
End With

Reply With Quote
  #2  
Old   
Vacuum Sealed
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-03-2011 , 06:55 PM






Phil

Goto Ron DeBruins site, he has what you need.

http://www.rondebruin.nl/tips.htm


http://www.rondebruin.nl/mail/folder3/message.htm

This is a snippet that will enable you mail a list of recipients in a range.

On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _

I use something similar.


HTH
Mick

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 05:19 AM



On 04/06/2011 00:55:17, "Vacuum Sealed" wrote:
Quote:
Phil

Goto Ron DeBruins site, he has what you need.

http://www.rondebruin.nl/tips.htm


http://www.rondebruin.nl/mail/folder3/message.htm

This is a snippet that will enable you mail a list of recipients in a
range.

On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _

I use something similar.


HTH
Mick


Thanks Mick.

I presume from your example that you are looping through the cells so that
you are sending a number of separate emails. I am trying to send the same
email to a number of people whose name is held in a single field. Ron's
solution of enclosing the names in quotation marks "Fred Smith; John Jones",
doesn't appear to work, neither does "Fred Smith" & ";" & "John Jones"

Phil

Reply With Quote
  #4  
Old   
Kaj Julius
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 06:31 AM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:isalrt$4lr$1 (AT) speranza (DOT) aioe.org...
Quote:
I use the following to send an email to various people.
When there is a single MailTo name (e.g. Fred Smith) it works fine
If I want to send it to Fred Smith and John Jones I have tried "Fred
Smith;
John Jones", but it only gets sent to the first person. John Jones in the
Outlook address book twice, and I get asked which one I want to use, so
Outlook is recognising both names. Do I need to do something with
Outlook.Recipients

Thanks

Phil

'Create a new mailitem and bring Outlook window to front
Set oItem = oOutlookApp.CreateItem(OLMailItem)
oItem.Display
FnSetForegroundWindow ("*outlook*")

With oItem
'Set the recipient for the new email
.To = MailTo
'Set the recipient for a copy
.CC = ""
'Set the subject
.Subject = Subject
ReadReceiptRequested equested = MsgRead ' Flag for message read
'The content of the document is used as the body for the email
If IsRtf = True Then ' Rtf message
.BodyFormat = olFormatHTML
.Body = ""
.HTMLBody = RTFText
Else ' Plain text
.HTMLBody = BodyText
End If

'Attachment is the attachment
If AttachmentsFound = True Then
For For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then
If Attach(j) > "" Then
Set olAttachment = .Attachments.Add(Attach(j))
End If
End If
Next j
End If
Call Call apWait(2, False) ' Time for the email to display before sending
.Send
End With
Maybe this article will be of use:

http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 08:06 AM



On 04/06/2011 12:31:58, "Kaj Julius" wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:isalrt$4lr$1 (AT) speranza (DOT) aioe.org...
I use the following to send an email to various people.
When there is a single MailTo name (e.g. Fred Smith) it works fine
If I want to send it to Fred Smith and John Jones I have tried "Fred
Smith;
John Jones", but it only gets sent to the first person. John Jones in the
Outlook address book twice, and I get asked which one I want to use, so
Outlook is recognising both names. Do I need to do something with
Outlook.Recipients

Thanks

Phil

'Create a new mailitem and bring Outlook window to front
Set oItem = oOutlookApp.CreateItem(OLMailItem)
oItem.Display
FnSetForegroundWindow ("*outlook*")

With oItem
'Set the recipient for the new email
.To = MailTo
'Set the recipient for a copy
.CC = ""
'Set the subject
.Subject = Subject
ReadReceiptRequested equested = MsgRead ' Flag for message read
'The content of the document is used as the body for the email
If IsRtf = True Then ' Rtf message
.BodyFormat = olFormatHTML
.Body = ""
.HTMLBody = RTFText
Else ' Plain text
.HTMLBody = BodyText
End If

'Attachment is the attachment
If AttachmentsFound = True Then
For For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then
If Attach(j) > "" Then
Set olAttachment = .Attachments.Add(Attach(j))
End If
End If
Next j
End If
Call Call apWait(2, False) ' Time for the email to display before sending
.Send
End With

Maybe this article will be of use:

http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx


Thanks for your help.
Thought I could get away with just putting all the names in the Outlook "To"
field, but it looks as if I have to run a loop and send each email
separately.

Anyway, problem solved, so thanks for your help and Mick's help

Phil

Reply With Quote
  #6  
Old   
Vacuum Sealed
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 09:01 AM



Phil

You can insert a range of cells.

Say you have the following

A1 Jack
A2 Jill
A3 Peter
A4 Paul
A5 Mary.

Dim mySendRange as string

mySendRange = ("A1:A5")

On Error Resume Next
With OutMail
.To = mySendRange
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _

You can even send different attachments to different peeps at once using an
Array.

Be sure to read thru Rons examples closely, he has several that will allow
you to send attachments and mail to multiple peeps, whether it be via the
To:, or CC, and even BCC, and you can insert Signatures also.


I use the following to send to multiple peeps in my range, and although it
doesn't have attachments included, you can add that to the code..

Sub sendEmail(smsAddress As String, smsWorkDay As String, smsName As String,
SmsStartTime As String, smsMessage As String)
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

strbody = "Hi " & smsName & " " & SmsStartTime & " start " & smsWorkDay
& " morning please ...{END}"

On Error Resume Next
With OutMail
.To = smsAddress
.CC = ""
.BCC = ""
.Subject = "Start Time"
.Body = strbody
.Display
'.send 'or use .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Sub sendEmails()

Dim smsAddress As String
Dim smsWorkDay As String
Dim smsName As String
Dim SmsStartTime As String
Dim smsMessage As String

For i = 4 To 29

smsAddress = Sheets("Main").Range("G" & i).Value
smsWorkDay = Sheets("Main").Range("E1").Value
smsName = Sheets("Main").Range("F" & i).Value
SmsStartTime = Sheets("Main").Range("E" & i).Value
smsMessage = Sheets("Main").Range("H" & i).Value

' If smsAddress = "" Then
' MsgBox (Sheets("Main").Range("G" & i).Value & " - does not have a valid
email, please change and retry")
' Exit For
' End If

If smsMessage = "Y" Then
Call sendEmail(smsAddress, smsWorkDay, smsName, SmsStartTime, smsMessage)
Sheets("Main").Range("I" & i).Value = "Y"
End If

Next i

End Sub

Reply With Quote
  #7  
Old   
Vacuum Sealed
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 09:05 AM



Doh...!!!

Phil

I kinda think I need a nanna-nap.....LMAO....

When I posted my reply, I neglected to take note of the fact that I was in
the Access NG and I am doling out Excel Codes......

My Bad....

Forget I even responded..

Sorry...

Reply With Quote
  #8  
Old   
Phil
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 12:40 PM



On 04/06/2011 15:05:19, "Vacuum Sealed" wrote:
Quote:
Doh...!!!

Phil

I kinda think I need a nanna-nap.....LMAO....

When I posted my reply, I neglected to take note of the fact that I was in
the Access NG and I am doling out Excel Codes......

My Bad....

Forget I even responded..

Sorry...


Hi Mick

Don't think it's relevant whether it's Access or Excel.
The critical thing is the Exact format of MySendRange. I presume it is the
names (not the email addresses) separated by a semicoln and space. Anyway,
doesn't seem to wor in Office 2010

Phil

Reply With Quote
  #9  
Old   
Ed Robichaud
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-04-2011 , 07:51 PM



This is not original, and I've lost the source - but I use a form with a
multi-select list box (load from some query) and the code below to send
blast mail to multiple recipients.

================================
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String

strEmail = Me.txtSelected & vbNullString
strMailSubject = Me.txtMailSubject & vbNullString
strMsg = Me.txtMsg & vbNullString & vbCrLf & vbCrLf & "your text here" &
_
'signature block
vbCrLf & "your text here" & _
vbCrLf & "your text here" & _
vbCrLf & "your text here"

DoCmd.SendObject , , , To:=strEmail, Bcc:=strEmail,
subject:=strMailSubject, MessageText:=strMsg

Err_cmdEmail_Click:
If Err.Number = 2501 Then
MsgBox " Email message cancelled ", vbExclamation
Else
' MsgBox Err.Description
Resume Exit_cmdEmail_Click
End If

Exit_cmdEmail_Click:
Exit Sub

End Sub

Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String

Me.cmdEmail.Enabled = True

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
Me!txtSelected = strList
End If
End With
End Sub
========================================
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
I use the following to send an email to various people.
When there is a single MailTo name (e.g. Fred Smith) it works fine
If I want to send it to Fred Smith and John Jones I have tried "Fred
Smith;
John Jones", but it only gets sent to the first person. John Jones in the
Outlook address book twice, and I get asked which one I want to use, so
Outlook is recognising both names. Do I need to do something with
Outlook.Recipients

Thanks

Phil

'Create a new mailitem and bring Outlook window to front
Set oItem = oOutlookApp.CreateItem(OLMailItem)
oItem.Display
FnSetForegroundWindow ("*outlook*")

With oItem
'Set the recipient for the new email
.To = MailTo
'Set the recipient for a copy
.CC = ""
'Set the subject
.Subject = Subject
ReadReceiptRequested equested = MsgRead ' Flag for message read
'The content of the document is used as the body for the email
If IsRtf = True Then ' Rtf message
.BodyFormat = olFormatHTML
.Body = ""
.HTMLBody = RTFText
Else ' Plain text
.HTMLBody = BodyText
End If

'Attachment is the attachment
If AttachmentsFound = True Then
For For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then
If Attach(j) > "" Then
Set olAttachment = .Attachments.Add(Attach(j))
End If
End If
Next j
End If
Call Call apWait(2, False) ' Time for the email to display before sending
.Send
End With

Reply With Quote
  #10  
Old   
Phil
 
Posts: n/a

Default Re: Email to more than 1 recipient - 06-05-2011 , 10:04 AM



Thanks, Ed

Which version of Access / Office are you using

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.