Android Question Send mail using SMTPClient from Net library

Hello.

I´m trying to implement a code to provide to users of my APP send my a mail to suggest modifications or errors.

My actual code, using Net library, and testing the mail send with my Gmail account, works properly, but Google lock each attempt to send a mail, because it don´t identifies who is trying to access to my Gmail Account.

How can I do this without be locked by Gmail Security?

It´s better use other platform?

Thank you!
 

JohnC

Expert
Licensed User
I would HIGHLY recommend using the code in this post:

And here's why:
  1. If you use your email server or gmail account, your app will need to include your login username/password. Even if you try to encrypt it, it is still possible to hack and then your own emails are compromised.
  2. If your "contact us" form has a place for the user to enter their email, then a good percentage of the time the user's email address will have a typo in it and then you can't get back in touch with them.
  3. Since the email is being sent from inside your app, the user might be suspicious of what other info is also being emailed to you because the user doesn't "see" the full email they will send to you.

However, by using the above code:
  1. It will invoke the USERS own email app (Regular email or Gmail - the users choice) and that means their return address will be 100% correct.
  2. Since the user will see the actual email being sent to you, they can be confident it is not sending undesired info.
 
Last edited:

drgottjr

Well-Known Member
Licensed User
it's a little confusing when you say it "works properly" because it looks like it isn't working at all. in any case, for you to use gmail as a mail sender (smtp), the sender has to be you. so, basically, you send the mail to yourself. identifying the actual sender would be trivial. you might want to set up a second gmail account specifically for this purpose.

i don't know if gmail is the only provider to offer this service; there may be others. but i'm pretty sure they're going to work in a similar fashion: only the account holder can send mail. nothing illegal about sending mail to yourself.

did you follow the instructions for setting up gmail as an smtp server? i know i have used it at some point, but i can't find the test app i tried it with.

i hope it's clear
 
I would HIGHLY recommend using the code in this post:

And here's why:
  1. If you use your email server or gmail account, your app will need to include your login username/password. Even if you try to encrypt it, it is still possible to hack and then your own emails are compromised.
  2. If your "contact us" form has a place for the user to enter their email, then a good percentage of the time the user's email address will have a typo in it and then you can't get back in touch with them.
  3. Since the email is being sent from inside your app, the user might be suspicious of what other info is also being emailed to you because the user doesn't "see" the full email they will send to you.

However, by using the above code:
  1. It will invoke the USERS own email app (Regular email or Gmail - the users choice) and that means their return address will be 100% correct.
  2. Since the user will see the actual email being sent to you, they can be confident it is not sending undesired info.
Thank you so much JohnC for your help.

I like a lot this solution.

As you said, I think it´s important for the user to know where is sending his mail, and not other data from his device is taken.
 
it's a little confusing when you say it "works properly" because it looks like it isn't working at all. in any case, for you to use gmail as a mail sender (smtp), the sender has to be you. so, basically, you send the mail to yourself. identifying the actual sender would be trivial. you might want to set up a second gmail account specifically for this purpose.

i don't know if gmail is the only provider to offer this service; there may be others. but i'm pretty sure they're going to work in a similar fashion: only the account holder can send mail. nothing illegal about sending mail to yourself.

did you follow the instructions for setting up gmail as an smtp server? i know i have used it at some point, but i can't find the test app i tried it with.

i hope it's clear
Maybe I´m not clear in my explanation, sorry. When I wrote "works properly", I tried to explain if Gmail locked my message it´s due to the code open the account, signed in and was locked. But as you said, finally the code doesn´t works because the mail wasn´t sent. You are right!;)👍

Thank you for you tips drgottjr !!!
 
I would HIGHLY recommend using the code in this post:

And here's why:
  1. If you use your email server or gmail account, your app will need to include your login username/password. Even if you try to encrypt it, it is still possible to hack and then your own emails are compromised.
  2. If your "contact us" form has a place for the user to enter their email, then a good percentage of the time the user's email address will have a typo in it and then you can't get back in touch with them.
  3. Since the email is being sent from inside your app, the user might be suspicious of what other info is also being emailed to you because the user doesn't "see" the full email they will send to you.

However, by using the above code:
  1. It will invoke the USERS own email app (Regular email or Gmail - the users choice) and that means their return address will be 100% correct.
  2. Since the user will see the actual email being sent to you, they can be confident it is not sending undesired info.
I have one more question about this...I have used a code similar yours, but B4A don't reconize sentences like this:

GetAppVersion
GetDeviceInfo
GetDeviceAPI

Should I add an additional library?
should I declare a variable to get this data?
I use the last version of B4A
 

JohnC

Expert
Licensed User
Those three lines send additional info on the user's device that might help you diagnose an issue they are having.

They are just small routines that just do what they say:

B4X:
Sub GetAppVersion As String
    Dim PM As PackageManager

    Try
        Return PM.GetVersionName(GetPackageName)
    Catch
        Return ""
    End Try
End Sub

Sub GetDeviceInfo As String
       Dim P As Phone

       Dim manu As String = p.Manufacturer
       Dim modl As String = p.Model
       Dim prod As String = p.Product

       Return manu & " - " & modl & " - " & prod

End Sub

Sub GetDeviceAPILevel () As Int
    Dim P As Phone
    Return p.SdkVersion
End Sub
 
Last edited:
Those three lines send additional info on the user's device that might help you diagnose an issue they are having.

They are just small routine that do what it says:

B4X:
Sub GetAppVersion As String
    Dim PM As PackageManager

    Try
        Return PM.GetVersionName(GetPackageName)
    Catch
        Return ""
    End Try
End Sub

Sub GetDeviceInfo As String
       Dim P As Phone

       Dim manu As String = p.Manufacturer
       Dim modl As String = p.Model
       Dim prod As String = p.Product

       Return manu & " - " & modl & " - " & prod

End Sub

Sub GetDeviceAPILevel () As Int
    Dim P As Phone
    Return p.SdkVersion
End Sub


I would like to add that in order to recognize the statements, I had to include the library "Phone.lib" .

Thank you so much!!
 
Top