B4J Question [SOLVED] smtp.Send and ExitApplication ... no email sent

pierrem

Member
Licensed User
Longtime User
Hi,

I'm probably missing something ...

B4X:
Private Sub sendGmail(nbl As Int)
If (File.Exists(xui.DefaultFolder,"gabuzomeu.dat") = False) Then Return
    Private localSmtp As String = kvs.Get("smtp")
    Private localPort As String = kvs.Get("port")
    Private localCompte As String = kvs.Get("compte")
    Private localPass As String = kvs.Get("pass")
    Private localService As String = kvs.Get("service")
    Private localUtilisation As String = kvs.Get("utilisations")
    
    Dim SMTP1 As SMTP
    SMTP1.Initialize(localSmtp, localPort, localCompte, localPass,localService)
    SMTP1.StartTLSMode = False
    SMTP1.UseSSL= True
    SMTP1.To.Add("bt.devis.java@gmail.com")
    SMTP1.HtmlBody = True
    SMTP1.Subject="Utilisation de Gabuzomeu par "&GetSystemProperty("user.name","")
    SMTP1.Body="Le fichier/devis utilisé est : "&fichierXL&" - "&nbl&" ligne(s) traitée(s)<br/>C'est la "&localUtilisation&"ème utilisation sur ce poste."
    'SMTP1.AddAttachment("chemin","fichier")
    Try
        Wait For (SMTP1.Send) Complete (Success As Boolean)
    Catch
        Log(LastException)
    End Try
    
End Sub

and
B4X:
        ... some woking code before ....
        Try
        classeur.Save(travailDir,fichierXL)                                                ' on sauvegarde les modifications
        classeur.Close                                                                                ' on ferme le classeur
        txtUtilisations.Text = txtUtilisations.Text +1
        kvs.Put("utilisations",txtUtilisations.Text)
        sendGmail(cptLigneLocal)
        'fx.ShowExternalDocument(File.GetUri(travailDir, fichierXL))                            ' on ouvre directement (dans Excel) le fichier
        'ExitApplication                                                                                ' terminato la fiesta !
    Catch
        Log(LastException)
        toast.Show("Le sommaire ne doit pas être ouvert dans Excel ...")
    End Try

When I uncomment fx.ShowExternalDocument(...) and ExitApplication .... the email is not sent (at least not received ...)

My mistake is probably in the 'wait for' instruction ....

thanks in advance
p
 

pierrem

Member
Licensed User
Longtime User
Also tried (from forum ...)

B4X:
   ...
   SMTP1.Initialize(localSmtp, localPort, localCompte, localPass,"smtp")
   ...
    Try
        'Wait For (SMTP1.Send) Complete (Success As Boolean)
        Wait For smtp_MessageSent(Success As Boolean)
    Catch
        Log(LastException)
    End Try

not working either ...
sub smtp_MessageSent is not called
 
Upvote 0

pierrem

Member
Licensed User
Longtime User
Working ...
But if log() is in SMTP_MessageSent, nothing is out printed in log window ?

Thks Erel
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you should not have a sub like this if you use waitfor.
 
Upvote 0
Top