Solved

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

Posted on 2013-12-06
12
1,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Supports up to 4K resolution!

The VS192 2-Port 4K DisplayPort Splitter is perfect for anyone who needs to send one source of DisplayPort high definition video to two or four DisplayPort displays. The VS192 can split and also expand DisplayPort audio/video signal on two or four DisplayPort monitors.

 

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 70

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This program is used to assist in finding and resolving common problems with wireless connections.
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses
Course of the Month8 days, left to enroll

617 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