Solved

VB script to send pop mail only performs intermittently

Posted on 2016-08-23
10
58 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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