Android Question Sending Email Using SMTP ?

eng.khalidvb

Member
Licensed User
Longtime User
Hello all,

I check many thread here and I got one example to send email using gmail (SMTP), but no error shows and no email received.

any idea ?

B4X:
Dim mail As SMTP
                mail.Initialize("smtp.gmail.com", 587, "[email protected]", "mypassword", "SMTP")
                mail.StartTLSMode = True
                mail.To.Add("[email protected]")
                mail.Subject = "This is the subject"
                mail.Body = "This is the message body."
                mail.Sender = "[email protected]" '<--------------------------------------------
                mail.Send
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Which library do you use for SMTP?
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
I did the same using visual studio - windows from application and it works so means no issue with email account and password.

here is the code:

B4X:
Dim Mail As New MailMessage
        Dim SMTP As New SmtpClient("smtp.gmail.com")

        Mail.Subject = "Security Update"
        Mail.From = New MailAddress("[email protected]")
        SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "MYPASSWORD") '<-- Password Here

        Mail.To.Add("[email protected]") 'I used ByVal here for address

        Mail.Body = "Test" 'Message Here

        SMTP.EnableSsl = True
        SMTP.Port = "587"
        SMTP.Send(Mail)

Here is my B4A Code:

B4X:
Dim mail As SMTP
                mail.Initialize("smtp.gmail.com", 587, "[email protected]", "MYPASSWORD", "SMTP")
                mail.StartTLSMode = True
                mail.To.Add("[email protected]")
                mail.Subject = "This is the subject"
                mail.Body = "This is the message body."
                mail.Sender = "[email protected]" '<--------------------------------------------
                mail.Send


any idea ?
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
You need to allow "less secure applications" in your gmail account.
Hi Erel I know this and I enable it and by using the same I am able to send email using visual studio and email received but in my B4A it wont send any mail.

I belive there is an issue with my code.
 
Upvote 0
Top