Solved

VB script to send pop mail only performs intermittently

Posted on 2016-08-23
10
62 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
[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
  • 5
  • 5
10 Comments
 
LVL 36

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 36

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 36

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 36

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 36

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

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