Mark,
What are you doing to prevent the app's run event from exiting the
application before the mail is sent? If you call the socket, and
don't do anything else, the app will quit before the socket has had a
chance to do much of anything.
I have a console app project that uses this code at the end of the
app.Run event handler:
while ubound(theSMTPSocket.messages) >= 0
ANDtheSMTPSocket.lastErrorCode = 0
App.DoEvents
wend
This prevents the app from quitting so long as there are messages
left to send, and no error has been encountered by the socket.
Does that help, or are you already doing something similar?
--Peter
On Sep 24, 2006, at 10:55 AM, Mark Levinson wrote:
I am trying to write a Form-to-Email CGI in RB, but console apps do
not appear to connect sockets like GUI apps can.
The following code works perfectly from the Action event of a
PushButton in a windowed (GUI) app, but does nothing when called
from the Run event in a Console App. Any suggestions?
(test this with your own email settings and password)
(Using RB 2006 release 3 Professional. MacBookPro 2.16 GHz
Intel, 2 Gig RAM, Tiger 10.4.7)
dim sock as new SMTPSocket
sock.address = "smtp.myhost.com"
sock.port =
587
'
sock.username = "[EMAIL PROTECTED]"
sock.Password = "[EMAIL PROTECTED]"
dim mail as new EmailMessage
mail.fromAddress = "[EMAIL PROTECTED]"
mail.addRecipient "[EMAIL PROTECTED]"
mail.subject = "[TEST]"
mail.bodyPlainText = "Testing..."
sock.messages.append mail
sock.SendMail
In either GUI or console app, the sock.isConnected property stays
false and the sock.LastErrorCode is zero (i.e. success), but mail
shows up at the destination when this is run from the GUI, but not
from the console App. Calling sock.connect does not correct the
problem.
So, I then subclassed SMTPSocket in both GUI and Console projects
so I could have access to the Events (ConnectionEstablished,
MessageSent, SendComplete, ServerError, etc.). I put some
trivial response code in each Event and set breakpoints on those
code lines to see if the Events are fired by the application when
the socket object is used. I then instantiated an object of
this subclass and ran the same code as you see above.
In the GUI, the Events are fired and the breakpoints do trap at
each SMTPsocket Event. However, in the Console App, the
breakpoints do not trap the Events, so I am assuming the Events are
never fired.
Other users have been successful with the POP3Socket in console apps.
Why does the Console App ignore these events for the SMTPSocket
class and fail to function?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>