Solved

VB script to send pop mail only performs intermittently

Posted on 2016-08-23
10
44 Views
Last Modified: 2016-08-26
I am a novice at scripting.  I have a script which is supposed to send me an Email when it is activated, but it only does that some of the time.  I'd appreciate guidance about improving this, so that the Email is sent consistently.  Below is the script.  Some of the text has been removed, so only ""  appears, in order to preserve privacy regarding contact information, passwords, etc.

Dim emailObj
Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = ""

emailObj.To       = ""

emailObj.Subject  = ""
emailObj.TextBody = ""

Dim emailConfig
Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.maui.net"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = false 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = ""
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = ""
emailConfig.Fields.Update

emailObj.Send

'If err.number = 0 then Msgbox "Done"

Open in new window

0
Comment
Question by:ddantes
  • 5
  • 5
10 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 41767254
Sadly, if you know for sure the script is fired correctly EVERY TIME (do it with writing extra code to append to a log file or something, log a line BEFORE the email procedure, and AFTER the email procedure, obviously have the lines be different, with a time stamp), then you need to know why the email is not delivered (some SMTP error, maybe quota or spam issues).
So on that PC or server, open Wireshark and capture port 25 only. Then at the end of the day, go through it all, and check why some have not been sent (probably got some SMTP error, post it here).
If the log file already isn't complete, it meant the script didn't execute correctly, and you need to find out why.
0
 

Author Comment

by:ddantes
ID: 41767414
Thank you for your advice.  I'm afraid I'll need to have the logging code specified, and instructions for using Wireshark.  I have no experience with either process.  If the script fails to connect to the server, there would be a popup on the host computer desktop, and there has not been any.  Alternatively, if there is a way to improve the existing code, that would be simpler for me.
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 41770197
Here's some code to get the log file going
Now you have to correspond the running script with TWO lines every time. If you're missing TWO lines, the script probably never ran. Check why.
 If the script RAN, but only one line is logged, the email part is giving errors.
If the script RAN, and still two lines logged, but no email received, you might not have a problem on your side, but maybe the other side (spam filter).

After you know what to look for, install Wireshark on the PC where this script runs (https://wireshark.org)
After default install (just press OK every step), ttart Wireshark. First click the correct network interface, then fill in the line above:

port 25

Let it run for a while. After you see email not being received again, close Wireshark, save the capture, rename to .txt, post here.


Const ForAppending = 8
Dim fso
Set fso=wscript.CreateObject("Scripting.FileSystemObject")
Dim objFile
Dim logfile
logfile = "C:\Users\Kimputer\Documents\logfile.txt"
if fso.fileexists(logfile) then
	Set objFile = fso.OpenTextFile(logfile, ForAppending, True)
else
	Set objFile = fso.CreateTextFile(logfile,  True)
end if

objFile.Write now() &  " - start email script" & vbcrlf

Dim emailObj
Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = ""

emailObj.To       = ""

emailObj.Subject  = ""
emailObj.TextBody = ""

Dim emailConfig
Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.maui.net"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = false 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = ""
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = ""
emailConfig.Fields.Update

emailObj.Send

'If err.number = 0 then Msgbox "Done"

objFile.Write now() & " - end email script (email should've been sent)" & vbcrlf

Open in new window

0
 

Author Comment

by:ddantes
ID: 41770603
Thank you for specific instructions.  I tested the script five times.  The Email was received three times.  The log file shows five identical entries like this:
8/25/2016 6:34:13 AM - start email script
8/25/2016 6:34:15 AM - end email script (email should've been sent)

After installing Wireshark, there was a window asking to select a capture filter.  I don't know what that requires.  I tried double clicking the first line below the "Enter a Capture Filter" line  ("Wireless Network Connection") and I'm embedding a screen shot.  I did not see an option to enter Port 25. screen shot
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 41770865
The "enter a capture filter" should be filled in after clicking the wireless network connection.

Port 25

Press enter to start. After testing again, and noticing 5 successful runs but receiving less emails, quit Wireshark, saving the capture file.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:ddantes
ID: 41771167
OK, there are five 2-line entries in the log file, but only 3 Emails were received.  The capture file has been saved, but I need to change its extension from .pcapng in order to upload it.  What extension shall I use?
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 41771454
use .txt, I  will download it, and rename it back.
0
 

Author Comment

by:ddantes
ID: 41771979
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 41772066
First of all, it's important you now CHANGE your POP3/SMTP password (or issue a password reset at your mail provider). Sorry for that.

Now on to the diagnostics. Sadly, EVERYTHING is working. Your mail was submitted FIVE TIMES CORRECTLY.
If you didn't receive it, either after submitting it at your SMTP server, it was stopped there, and never sent to the recipient (if it was the SMTP server of your ISP, and not the receiving SMTP server of the recipient).
Other option is, either if the SMTP server was already the receiving one, or not, doesn't really matter, the message was stopped by a filter before it was dropped in the mailbox.
The mail provider should be able to give you more info why you didn't receive it, or you should be able to tell yourself if you have full control of the spam solution used (either your own PC/Outlook/etc, or the spam filter found on the webmail interface).

For now, you did it mostly correct, the script is firing correct, as are the email messages transmitted correctly. The question now is why it's being intercepted. You could try to have your email having an actual body. Sometimes spam filters don't like emails with only a subject and no body. Other than that you can't do much about it, and your course of action is to see how to whitelist it.
0
 

Author Comment

by:ddantes
ID: 41772087
Thank you for your clear and detailed assistance!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
What is Usenet? There are many different opinions on exactly what Usenet is an isn't. Many opinions are incorrect simply out of ignorance. The Wikipedia listing about Usenet does a good job of explaining it, so instead of repeating it all here I wi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now