Solved

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

Posted on 2013-12-06
12
929 Views
Last Modified: 2014-06-10
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
0
Comment
Question by:100questions
  • 4
  • 3
12 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39701194
This is sending an smtp message.  It is nothing to do with any mailbox so it won't go into any sent box.

Options.

1. Send scripted using Outlook from a client or whatever you are using for your mail system using a mailbox configured on there.
2. Add a Blind copy to the message to a logs@yourdomain.com mailbox or similar.

Then in that mailbox either just leave them be or add rules to the mailbox to shift mails based on the address/subject etc. into suitable folders.

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

Steve
0
 

Author Comment

by:100questions
ID: 39701644
Thanks, what do you mean by send scripted in option 1?  Outlook would be a good option.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39701802
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
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:100questions
ID: 39718695
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39718704
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

0
 

Author Comment

by:100questions
ID: 39746717
I suppose this might work, have not tested it yet.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40117827
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40117828
I'd suggest accept dragon-it http:#39701194

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

Steve
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question