B4A Library New Net library - Android FTP, SMTP and POP3

Status
Not open for further replies.

Philip Prins

Active Member
Licensed User
Longtime User
You might need to allow access to "less secure" apps in your gmail account.

I used the SMTP function 1.54 with B4A but since the 1st of september 2015 i get the following error when sending email with gmail.

Delivery to the following recipient failed permanently:

emailadress@outlook.com

Technical details of permanent failure:
Internal parse error: Illegal envelope To: address (not valid RFC5321 syntax): emailadress@outlook.com
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested it with this code and it sent successfully:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As SMTP
   s.Initialize("smtp.gmail.com", 465, "xxx@gmail.com", "xxxx", "s")
   s.To.Add("test@test.com") 'change to real address
   s.Body = "123123123"
   s.UseSSL = True
   s.Send
End Sub

Sub s_MessageSent(Success As Boolean)
   Log(Success)
   Log(LastException)
End Sub
 

ivanomonti

Expert
Licensed User
Longtime User
I tried them all with gmail, but the result is always false, not send


B4X:
Sub btalert_click
   
    Dim bt As Button = Sender
    Dim ls As List = bt.Tag
   
    If ls.Get(0) = "" Or ls.Get(1) = "" Or ls.Get(2) = "" Then
        Msgbox("Compilare tutti i campi, email, telefono e nome, grazie per la vostra attenzione.", "Attenzione")
        Return
    End If
   
    Dim SMTP As SMTP
    SMTP.Initialize("smtp.gmail.com", 587, "xxxxxxxxxxxxxxx@gmail.com", "xxxxxxxxxxxxxxxxxx", "SMTP")
    SMTP.StartTLSMode = True
   
    Log(ls.Get(0) & " " & ls.Get(1) & " " & ls.Get(2))

    Try
        'SMTP.UseSSL = True
        SMTP.To.Add(ls.Get(0))
        SMTP.BCC.Add("ivanomonti@gmail.com")
            SMTP.Subject = "Informazioni generali del servizio"
        SMTP.Body = "Desidero avere più informazioni a riguardo il progetto Human Equality" & Chr(10) & "Mio contatto telefonico: " & ls.Get(1) & Chr(10) & "Mio nome: " & ls.Get(2) & Chr(10) & "Cordiali saluti a sentirci presto"
        'SMTP.AddAttachment(File.DirRootExternal & "/Encuestas", exportfile)
        SMTP.Send
    Catch
        Log("Text file not sent")
    End Try
   
End Sub

Sub SMTP_MessageSent(Success As Boolean)
  If Success=True Then Msgbox("Il vostro messaggio è stato inviato correttamente, grazie per la fiducia dataci.", "Human Equality")
  If Success=False Then Msgbox("Il vostro messaggio non è stato inviato correttamente, riprovi più tardi.", "Human Equality")
End Sub
 

ivanomonti

Expert
Licensed User
Longtime User

error:
530 5.5.1 https://support.google.com/mail/answer/14257 qq4sm10900719wjc.14 - gsmtp
 

ivanomonti

Expert
Licensed User
Longtime User
change service SMTP

setting service operatgor

B4X:
'    Secure SSL/TLS Settings
'    (Recommended)
'    Username:    info@humanequality.eu
'    Password:    Use the email account’s password.
'    Incoming Server:    gator4098.hostgator.com
'    IMAP Port: 993
'    POP3 Port: 995
'    Outgoing Server:    gator4098.hostgator.com
'    SMTP Port: 465
'    Authentication Is required For IMAP, POP3, And SMTP.

Code B4x

B4X:
Sub btalert_click
   
    ProgressDialogShow("Send Message...")
   
    Dim bt As Button = Sender
    Dim ls As List = bt.Tag
   
    If ls.Get(0) = "" Or ls.Get(1) = "" Or ls.Get(2) = "" Then
        Msgbox("Compilare tutti i campi, email, telefono e nome, grazie per la vostra attenzione.", "Attenzione")
        Return
    End If
   
'    Secure SSL/TLS Settings
'    (Recommended)
'    Username:    info@humanequality.eu
'    Password:    Use the email account’s password.
'    Incoming Server:    gator4098.hostgator.com
'    IMAP Port: 993
'    POP3 Port: 995
'    Outgoing Server:    gator4098.hostgator.com
'    SMTP Port: 465
'    Authentication Is required For IMAP, POP3, And SMTP.

    Dim SMTP As SMTP
    SMTP.Initialize("gator4098.hostgator.com", 465, "info@humanequality.eu", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "SMTP")
    SMTP.StartTLSMode = True
   
    Log(ls.Get(0) & " " & ls.Get(1) & " " & ls.Get(2))

    Try
        SMTP.UseSSL = True
        SMTP.To.Add(ls.Get(0))
        SMTP.BCC.Add("info@humanequality.eu")
            SMTP.Subject = "Informazioni generali del servizio"
        SMTP.Body = "Desidero avere più informazioni a riguardo il progetto Human Equality" & Chr(10) & "Mio contatto telefonico: " & ls.Get(1) & Chr(10) & "Mio nome: " & ls.Get(2) & Chr(10) & "Cordiali saluti a sentirci presto"
        SMTP.Send
    Catch
        Log("Text file not sent")
    End Try
   
End Sub

MessageSend

B4X:
Sub SMTP_MessageSent(Success As Boolean)
    ProgressDialogHide
      If Success=True Then Msgbox("Il vostro messaggio è stato inviato correttamente, grazie per la fiducia dataci.", "Human Equality")
      If Success=False Then Msgbox(LastException, "Human Equality")
    Log(LastException)
End Sub

Error LastException

B4X:
(SocketTimeoutException) java.net.SocketTimeoutException
 

ivanomonti

Expert
Licensed User
Longtime User
You need to allow unsecure connections to gmail in your gmail account.

Here I changed the mail server is the problem remains


' Secure SSL/TLS Settings
' (Recommended)
' Username: info@humanequality.eu
' Password: Use the email account’s password.
' Incoming Server: gator4098.hostgator.com
' IMAP Port: 993
' POP3 Port: 995
' Outgoing Server: gator4098.hostgator.com
' SMTP Port: 465
' Authentication Is required For IMAP, POP3, And SMTP.

B4X:
DimSMTPAsSMTPSMTP.Initialize("gator4098.hostgator.com", 465, "info@humanequality.eu", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "SMTP")
SMTP.StartTLSMode = True
 

Greg Shannon

Member
Licensed User
Longtime User
Hi,

I've been using this library successfully to emails from various email accounts. Recently (last few months) I've been having trouble with gmail, the problem is that only the first receipent will receive the email. The email will not get sent to any additional receipent, doesn't matter if the additional receipents are in the To, CC, or BCC fields.

When sending using hotmail, yahoo and other's I've tried, all receipents will receive the emails, this is just a problem with gmail.

Allow unsecure connections is turned on on the gmail account.

I've tried port 465 with UseSSL = true and port 587 with StartTLSMode = true, in both cases the email is sent successfully to only the first receipent.

In my sent folder in gmail, I can see the message and it shows a list of all the receipents that it should of been sent to.

No failure message of any kind is received.

Any ideas? Is anybody else getting the same results when using gmail?
 

Greg Shannon

Member
Licensed User
Longtime User
Thanks you for your response, knowing it work let me know I was doing something wrong. It turned out that my email addresses started with a space, as I was spliting them out of one string to add them to the receipents list. Triming the email address before adding them fixed the problem. I guess gmail no longer supports the white space before the email address.
 

rleiman

Well-Known Member
Licensed User
Longtime User
I started to use the Net library to send an email from my app then Google sent me an email stating I should use a secure app like the gmail app. Google stopped my app from signing into my gmail account.

How can I bypass this restriction?

Here is the coding I'm using (password and email is not the real ones)

In Sub Globals:

B4X:
    Private Email As SMTP

In Sub Activity_Create:

B4X:
    Email.Initialize("smtp.gmail.com", 587, "myemail@gmail.com", "mypassword", "SMTP")
    Email.StartTLSMode = True

B4X:
    Email.To.Add("someonesemail@gmail.com")
      Email.Subject = "This is the subject"
      Email.Body = "This is the message body."
      Email.AddAttachment(File.DirRootExternal, "apdfdocument.pdf")
      Email.Send

How can I code this so Google will allow me to send emails through the app?
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Don,

I've tried port 465 with UseSSL = true and port 587 with StartTLSMode = true but Google still sends the email that I'm blocked from using gmail in my app to access my gmail account to send the email.

Do you have a small working sample app (leaving out your email and password) I can test by replacing those details with mine?

Looks like Google has implemented some new security.
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Don,

I looked and tried what other people have done without success. I hope someone who recently used gmail and this lib will post some sample code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…