Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Log Sent Email in the Sent Items folder on server when sending VBScript emails

Currently, this script does not log the Sent emails to my knowledge.
I need for this script to be modified so that it records or shows the sent email sin the Sent Items folders on the Exchange server.

MailTo = "email@email.com"
From = "email@email.com"
Subject = "Test Email"
Body = "This is an VBScript -       Test."
Username = "user"
Password = "password"
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") = "server"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
      .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      .Update
 End With
 objMessage.Send
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of E=mc2

ASKER

Thanks, what do you mean by send scripted in option 1?  Outlook would be a good option.
Rather than sending an smtp message, connecting to and installation of outlook on the machine in question, connect to a mailbox, create a message and hit send effecively.

Much easier to do what I suggested with a bcc and rule in whatever mailbox watned.
Steve
Avatar of E=mc2

ASKER

Thanks.  where would I place in the original script, your code:
With objMessage
  .Subject = Subject
  .From = From
  .To = MailTo
  .TextBody = Body
  .bcc = "logs@mydomain.com"
End With
Seriously?

Your code:

 With objMessage
  .Subject = Subject
  .From = From
  .To = MailTo
  .TextBody = Body
 End With

Open in new window


Suggested change:

With objMessage
  .Subject = Subject
  .From = From
  .To = MailTo
  .TextBody = Body
  .bcc = "logs@mydomain.com"
End With

You can make things into your SUB as an option if you wish:

MailTo = "email@email.com"
BCC = "log@email.com"
From = "email@email.com"
Subject = "Test Email"
Body = "This is an VBScript -       Test."
Username = "user"
Password = "password"

Email MailTo, Bcc, From, Subject, Body, Username, Password

Sub Email (MailTo, BCC, From, Subject, Body, Username, Password)
 Set objMessage = CreateObject("CDO.Message")
 With objMessage
  .Subject = Subject
  .From = From
  .To = MailTo
  .TextBody = Body
  .Bcc = BCC
 End With
 With objMessage.Configuration.Fields
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
      .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      .Update
 End With
 objMessage.Send
End Sub 

Open in new window


Or remove all the temporary variables:

Body = "This is an VBScript -       Test." 

Email "myto@email.com","mybcc@email.com","myfrom@email.com","Subject line",Body, "username","password"

Sub Email (MailTo, BCC, From, Subject, Body, Username, Password)
 Set objMessage = CreateObject("CDO.Message")
 With objMessage
  .Subject = Subject
  .From = From
  .To = MailTo
  .TextBody = Body
  .Bcc = BCC
 End With
 With objMessage.Configuration.Fields
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = user
      .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      .Update
 End With
 objMessage.Send
End Sub 

Open in new window

Avatar of E=mc2

ASKER

I suppose this might work, have not tested it yet.
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
I'd suggest accept dragon-it http:#39701194

You've been busy with the cleanups Qlemo, can't keep up with the emails!!

Steve