To begin, let me please say that I have researched this issue, and as you will see, believe that I have coded everything correctly based on posts from other very knowledgeable users. That said, my hair is kept short to keep me from pulling it out.
The problem. I have a console app that runs as a Windows service. It has been running for quite some time, as has another service that uses the same code. This service, among other things, sends status emails when it is processing data transactions. I have been adding capabilities recently, and suddenly last week it was no longer able to send any outgoing emails. None. Nada. Zip. I made no changes to the routine that sends these emails, so this was particularly troubling.
After much hair pulling I decided to drop the routine that sends the emails into a windowed app to test it, and behold, it worked! I then dropped the exact same code into a console app and it did not work!
For this testing I am using hMail server on the same desktop as the IDE, as I like the logging info and do not have to worry about firewall issues. The message for failures is: The read operation failed. Bytes transferred: 0 Remote IP: 127.0.0.1
Now for the meat. Below is the routine that sends the email. In the console app, the Run event calls SendEmail with a subject and message. That’s it. If I don’t have the For-Next loop right after send message, the email fails. As you can see, the While loop polling the socket is present, as per other postings, and always has been. It does not, however, seem to be working.
Will someone please tell me what I am doing wrong, and if you can, why this routine (minus the For-Next loop) has been working for weeks without a hitch? I have now burned a day on a time sensitive project that really isn’t about this email. I have only so much hair to pull.
Thanks,
Matthew
[code]’ Send an email as requested
Dim i as Integer
dim dtmNow as new Date
Dim msgMail as EmailMessage
Dim sckSMTP as SMTPSecureSocket
’ Create an instance:
sckSMTP = new SMTPSecureSocket
sckSMTP.Address = “127.0.0.1”
sckSMTP.port = 25
sckSMTP.Username = “^^^^^^^^^^^^^^”
sckSMTP.Password = “**************”
’ Create a new message
msgMail = New EmailMessage
’ Sender and Subject
msgMail.fromAddress= “sender@email.net”
msgMail.subject= strSubject
’ The message
msgMail.bodyPlainText = strMessage
’ Add Recipient(s)
msgMail.AddRecipient “recipient@email.com”
’ Add it to list of messages
sckSMTP.messages.append msgMail
’ Send message
sckSMTP.SendMail
’ This should NOT be necessary
for i = 1 to 100
app.DoEvents
sckSMTP.poll
next
’ Wait for the sending to be done if youre going to send another
while sckSMTP.BytesLeftToSend > 0
sckSMTP.poll
wend[/code]