Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Oct 16, 2019 11:52 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: SMTP From CGI.
PostPosted: Mon Sep 17, 2012 2:19 pm 
Offline

Joined: Fri Jul 20, 2012 2:09 pm
Posts: 33
Hey guys trying to send an email from a CGI application.
This is my code:
Dim mail as EmailMessage
dim smtp as smtp
smtp = new smtp
smtp.address = "mail.bttb.net.bd"
smtp.port = 25

mail = New EmailMessage
mail.fromAddress="myrealemail"
mail.subject="hello world"
mail.bodyPlainText = "PLAIN"
mail.bodyHTML = "<strong>HTML</strong>"
mail.headers.appendHeader "X-Mailer","RB Mail"


mail.addRecipient Trim("myemail")


//send the mail
smtp.messages.append mail //add email to list of messages
smtp.SendMail //send message

while smtp.BytesLeftToSend > 0
Context.print("Left to send: " + str(smtp.BytesLeftToSend) )
smtp.Poll
wend
Context.print("Error code:" + str(smtp.LastErrorCode) )


I added a class to my project called smtp with as super SMTPSocket1, however this didn't help.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Mon Sep 17, 2012 5:21 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
UserName and Password ?

Make sure you are using the correct port for the emailing service.

You may also need to verify that your ISP isn't blocking the emailing port.

I'm sure there are many posts about emailing which you probably should read.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Tue Sep 18, 2012 3:25 am 
Offline

Joined: Fri Jul 20, 2012 2:09 pm
Posts: 33
J.Sh3ppard wrote:
UserName and Password ?

Make sure you are using the correct port for the emailing service.

You may also need to verify that your ISP isn't blocking the emailing port.

I'm sure there are many posts about emailing which you probably should read.

Username and password aren't needed for public SMTP's (the one in the example is random however I tried to use my ISP's one that worked before).

I've read lots of posts however it's all about how you need that loop at the end.

Error code is 0 btw.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Tue Sep 18, 2012 12:24 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Try adding a time delay in that loop so it's not being called too fast repeatedly.

Make sure your delay is long enough for the email to be sent off.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Tue Sep 18, 2012 2:11 pm 
Offline

Joined: Fri Jul 20, 2012 2:09 pm
Posts: 33
J.Sh3ppard wrote:
Try adding a time delay in that loop so it's not being called too fast repeatedly.

Make sure your delay is long enough for the email to be sent off.


How would I do a proper delay if smtp.BytesLeftToSend returns 0.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Tue Sep 18, 2012 7:43 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
kript0x wrote:
J.Sh3ppard wrote:
Try adding a time delay in that loop so it's not being called too fast repeatedly.

Make sure your delay is long enough for the email to be sent off.


How would I do a proper delay if smtp.BytesLeftToSend returns 0.



Hi.


I am also seeing 0 always returned but I am not sure if it's a bug.

My email is very short and I don't know if BytesLeftToSend shows you the first bytes sent or if it executes after the first send... "Bytes Left To Send" not "All Bytes totally sent".

Forget using a timed delay, using socket.poll will work and is the correct way to do this.

Don't use BytesLeftToSend to control your while loop.

Use a boolean flag to control your while loop.
Create a boolean flag as a property of app, set it true on run.


While app.Stay_Alive=true
If smtpsock <> nil then
smtpsock.poll
else
print "Did not create socket"
end
Wend


Set the flag to false after the email has been sent using the socket's mail sent event.
That will end your app after the email was successfully sent.

Don't build your email and socket in the while loop.
Don't repeatedly send your email in the while loop either.




I just did this test and sent emails successfully using :
Mac OS X 10.6.8 RS 2012_R1 console with smtpsecure socket with gmail.


Top
 Profile  
Reply with quote  
 Post subject: Re: SMTP From CGI.
PostPosted: Wed Sep 19, 2012 5:38 am 
Offline

Joined: Fri Jul 20, 2012 2:09 pm
Posts: 33
J.Sh3ppard wrote:
kript0x wrote:
J.Sh3ppard wrote:
Try adding a time delay in that loop so it's not being called too fast repeatedly.

Make sure your delay is long enough for the email to be sent off.


How would I do a proper delay if smtp.BytesLeftToSend returns 0.



Hi.


I am also seeing 0 always returned but I am not sure if it's a bug.

My email is very short and I don't know if BytesLeftToSend shows you the first bytes sent or if it executes after the first send... "Bytes Left To Send" not "All Bytes totally sent".

Forget using a timed delay, using socket.poll will work and is the correct way to do this.

Don't use BytesLeftToSend to control your while loop.

Use a boolean flag to control your while loop.
Create a boolean flag as a property of app, set it true on run.


While app.Stay_Alive=true
If smtpsock <> nil then
smtpsock.poll
else
print "Did not create socket"
end
Wend


Set the flag to false after the email has been sent using the socket's mail sent event.
That will end your app after the email was successfully sent.

Don't build your email and socket in the while loop.
Don't repeatedly send your email in the while loop either.




I just did this test and sent emails successfully using :
Mac OS X 10.6.8 RS 2012_R1 console with smtpsecure socket with gmail.


Hah that worked! How did I not think of that myself...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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