none
BCC in VBS Email Script RRS feed

  • Question

  • I would like to add a BCC list of emails to an existing VBS Email script.

    What command do I use to add this in, or how can I add it in?

    Thank you.

    Monday, October 8, 2018 6:43 PM

Answers

All replies

  • Just add it to the BCC field of the "message" object.

    cdoMsg.BCC = "user@domain.com;uswr2@domain.com;user3@domain.com"


    \_(ツ)_/

    Monday, October 8, 2018 7:15 PM
  • Thanks very much, so how would I fit that in the following code:

    SubjectDate = InputBox("Date to be added to the subject:", "Enter date")
    MailTo = "email1@gmail.com"
    From = "mainemail@someprovider.com"
    Subject = "This is a test " & SubjectDate
    Body = "Hi, This is an VBScript to send email, Regards, User."
    Username = "mainemail@someprovider.com"
    Password = "passwordhere"
    Email MailTo, From, Subject, Body, Username, Password
    
    Sub Email (MailTo, From, Subject, Body, Username, Password)
     Set objMessage = CreateObject("CDO.Message")
     With objMessage
      .Subject = Subject
      .From = From
      .To = MailTo
      .TextBody = Body
     End With
     With objMessage.Configuration.Fields
          .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.com"
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
          .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mainemail@someprovider.com"
          .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "passwordhere"
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
          .Update
     End With
     Set objFSO = CreateObject("Scripting.FileSystemObject")
     Set objFolder = objFSO.GetFolder("C:\Attachment\")
     Set colFiles = objFolder.Files
     For Each objFile in colFiles
      objMessage.AddAttachment objFile.Path
     Next
     objMessage.Send
    End Sub
    

    Monday, October 8, 2018 7:41 PM
  •  With objMessage
      .Subject = Subject
      .From = From
      .To = MailTo
      .TextBody = Body
      .BCC = "user@domain.com;uswr2@domain.com;user3@domain.com"
     End With

    That would be the easiest place. Or you could assign it to a variable at the top and then reference the variable in the With like how the other variables are used.

    Monday, October 15, 2018 4:54 AM