Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 21, 2019 1:48 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: SMTPSocket from Windows Service
PostPosted: Thu Aug 09, 2012 6:41 pm 
Offline

Joined: Thu Aug 09, 2012 6:13 pm
Posts: 2
I am having an issue get my windows service app to send emails. The service will check a storage location and determine the percentage utilized. Once a thresh hold has been meet it will email out an alert. The first part of the App works fine as I have it report out the percentage in the System.DebugLog and verified from the DebugViewer. But when it runs the EmailReport method I can see from the DebugViewer I get the following output when it tries to send the email "swi_lsp: non-browser app; disable" I am running this service app on a Window-7 64bit system.

I created a class called "nSMTPsocket1" as a SMTPSocket.

Sub EmailReport()
Dim FI2 As FolderItem
Dim TIS As TextInputStream
Dim mail As EmailMessage
Dim Q, LoopX As Integer
Dim Email, EmailAddr As String
Dim cArray(-1) As String
Dim SMTPsocket1 As New nSMTPsocket1

mail = New EmailMessage

SMTPsocket1.Address = "mail.unknown.com"
SMTPsocket1.Port = 25

FI2 = GetFolderItem("email.cfg")
TIS = TextInputStream.Open(FI2)

Q = 0

Do Until TIS.EOF
EmailAddr = TIS.ReadLine
If EmailAddr.Left(1) <> "#" Then
ReDim cArray(Q)
cArray(Q) = EmailAddr
Q = Q + 1
End If
Loop

Email = "Test from windows service app."

mail.fromAddress="support@unknown.com"
mail.subject="Storage Utilization Alert!!"
mail.BodyPlainText = Email
mail.headers.appendHeader "X-Mailer","REALbasic SMTP"

LoopX = 0
Do Until LoopX > UBound(cArray)
mail.AddRecipient cArray(LoopX)
LoopX = LoopX + 1
Loop

SMTPsocket1.messages.append mail
SMTPsocket1.sendMail
SMTPsocket1.Disconnect


Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTPSocket from Windows Service
PostPosted: Thu Aug 09, 2012 6:49 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You're not giving the socket enough time to send anything. SendMail is an asynchronous process. It will return immediately, before the sending has already begun. Then you disconnect immediately. Also, Smtpsocket1 is a local variable, which will be destroyed as soon as the method finishes, and before the mail is sent. Make it a global property instead. You do not need to explicitly disconnect; the socket will disconnect after it sends the mail.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTPSocket from Windows Service
PostPosted: Fri Aug 10, 2012 5:44 pm 
Offline

Joined: Thu Aug 09, 2012 6:13 pm
Posts: 2
Thank you very much for the info and advice.

After trouble shooting my issue further and stripping down the code I found this out.

Test application looks like this. Started from the "Empty Service.rbp" file.

App.Run()
System.DebugLog("Start of Run")

Dim TMR As new SrvcTimer
TMR.Mode = 2
TMR.Period = 30000

While True
App.DoEvents
Wend


Created new Class "SrvcTimer" set to Timer
SrvcTimer.Action()
System.DebugLog("Timer Action")


If I install this as a windows service and then start the service I get the following error that repeats.
Quote:
[5500] Start of Run
[5500] Runtime Error
[5500] Please report what caused this error along with the information below.
[5500] ../../../Common/ThreadInvoker.cpp: 145
[5500] Failure Condition: IsRBThread() && CurrentThreadHandlesEvents()


If I just double click on my application and lauch it. It runs and from the DebugViewer I can see the DebugLog enteries as the timer cycles every 3 secs.
Quote:
[5996] Start of Run
[5996] Timer Action
[5996] Timer Action
[5996] Timer Action
[5996] Timer Action


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group