B4J Question Using SMTP

MarrowZero

Member
Licensed User
Hello,

I'm attempting to build an app to test if SMTP details are working. I'm troubleshooting a client problem where sending to smtp.office365.com is either taking more than 20 seconds or failing with some message. My plan here is a build a small app that can send 1 msg per minute and log success/failure. This will help cut the problem in half, ie is this a computer, av, network, firewall or Microsoft screwing about (again). The app could be run at another location to again help diagnose the situation.
I did originally started in Powershell and then I thought - why not try in B4X ?!?!

Questions

How to set a timeout for the connection?
- For example if host does not exist or using a different port
- 3 seconds should be enough

How can I log the "raw" responses from the SMTP server?
- For example to see the rejection that the username/password was incorrect
- 220 LO2P123CA0075.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 19 Jan 2022 16:38:43 +0000


How to set the TLS/Cipher version used?


Many thanks for any help
--Paul



SMTP testing:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Dim SMTP As SMTP
    
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
    SMTP.Initialize("smtp.office365.com", 587, "the_username","the_password","SMTPevent")
    SMTP.UseSSL = False
    SMTP.StartTLSMode = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.


Sub CreateEMail
    SMTP.AuthMethod=SMTP.AUTH_LOGIN
    SMTP.To.Add("[email protected]")
    SMTP.Subject = "Testing SMTP Issue"
    SMTP.Body = "Testing the email send issue"
    SMTP.Send
    
End Sub


Private Sub Button1_Click
    CreateEMail
    
End Sub
 

ThRuST

Well-Known Member
Licensed User
Longtime User
@MarrowZero There's no need to invent the wheel since there's better solutions ;) You should better use my B4Xemail Library.
Refuel your jetpack and head over to this page >here<

??‍♂️ -=[ThRuST]=-
 
Upvote 0
Top