Sendmail not working second time

I am trying to send an email from a website through the outlook server. It works fine to send one email, but if I try to send a second email it fails. I’ve tried different permutations, but here’s my current code:

mailServer.address = “
mailServer.port = 587
mailServer.username =
mailServer.password =
mailserver.Connect 'don’t know if this is actually needed

if mailserver.Messages.Ubound>-1 then
’ if a previous message exists, this should clear it
end if

admmail.addRecipient tmpEmail
'admmail.headers.appendHeader “X-Mailer”,“Match SMTP” 'added in open event of webpage
admmail.subject=webpage1.curlocation+" conference information"
admmail.BodyHTML="Here is information on the conference you requested :


mailServer.messages.append admmail

admmail and mailserver are both properties of the webpage so should not go out of scope before sending. After sending the first time, there is an lasterrorcode of 102, which I’m not sure is significant. But after trying to send a second time, there is an error code of 336031996. I have also tried with the gmail server, and I get exactly the same result and error codes.

Any help would be appreciated.

I would remove the mailserver.connect line and create a new instance of the mailserver object at the top.

Take the admmail property off the window and create it directly in the routine. I’ll bet that the socket is still sending the previous one and when you send the second they’re conflicting. Basically you’re changing the original message instead of creating a new one each time.

Thanks for the replies. Creating a new instance of the mailserver within the routine does appear to work. I am concerned, though, about the mailserver going out of scope before sending. I’ve read that an SMTP socket control should be an app or webpage object so it doesn’t go away before completing. However, in testing so far, going out of scope has not happened.