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, "eng.khalidvb@gmail.com", "mypassword", "SMTP")
                mail.StartTLSMode = True
                mail.To.Add("eng.khalidvb@gmail.com")
                mail.Subject = "This is the subject"
                mail.Body = "This is the message body."
                mail.Sender = "eng.khalidvb@gmail.com" '<--------------------------------------------
                mail.Send
 

hatzisn

Expert
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("eng.khalidvb@gmail.com")
        SMTP.Credentials = New System.Net.NetworkCredential("eng.khalidvb@gmail.com", "MYPASSWORD") '<-- Password Here

        Mail.To.Add("fatma.talabat@gmail.com") '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, "eng.khalidvb@gmail.com", "MYPASSWORD", "SMTP")
                mail.StartTLSMode = True
                mail.To.Add("fatma.talabat@gmail.com")
                mail.Subject = "This is the subject"
                mail.Body = "This is the message body."
                mail.Sender = "eng.khalidvb@gmail.com" '<--------------------------------------------
                mail.Send


any idea ?
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
check your gmail, you could be getting a security warning
 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…