SendMail

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

SendMail

Post by Pat »

I have used Hans SendMail ( i think it's Hans, apologies if not) a lot in recent years.
What i want to do is to send it to BCC and to TO.
What code do i need to do that?

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Re: SendMail

Post by Carol W. »

Pat,

Here is an excerpt from a routine that I use to SendMail. Hans did help me with parts of it. Note that I use the Bcc field but not the To field.

Code: Select all

Set objOutlook = CreateObject("Outlook.Application", "localhost")

  rstMembers.MoveFirst
  Do While Not rstMembers.EOF
    If Not IsNull(rstMembers!strE_MAIL) Then
      strBcc = strBcc & rstMembers!strE_MAIL & ";"
      lngCounter = lngCounter + 1
      If lngCounter Mod 300 = 0 Then
        Set objEmail = objOutlook.CreateItem(olMailItem)
        With objEmail
          .BCC = strBcc
          .Subject = strSubject
          .HTMLBody = strmsg
          '.Send 'Will cause warning message
          .Display
   '        MsgBox "Please click OK when the e-mail has been sent.", vbInformation
        End With
        strBcc = ""
      End If
    End If
    
    
    rstMembers.MoveNext
  Loop
I'm just guessing here but to send to the To Field, I would add

Code: Select all

.To  = strToaddresses 
within the With / End With set. strToaddresses would be a string containing the To addresses.

Hope this helps.
Carol W.

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: SendMail

Post by Pat »

Thanks Carol

User avatar
HansV
Administrator
Posts: 78557
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SendMail

Post by HansV »

You can use any combination of To, CC and BCC addresses:

Code: Select all

  Dim strTo As String
  Dim strCC As String
  Dim strBCC As String
  ...
  ...
  strTo = ...
  strCC = ...
  strBCC = ...
  Set objEmail = objOutlook.CreateItem(olMailItem)
  With objEmail
    .To = strTo
    .CC = strCC
    .BCC = strBCC
    ...
    ...
  End With
Simply leave the strings you don't need blank, or omit them altogether.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: SendMail

Post by Pat »

Good to know, thanks Hans