Android Question help with email sender

piero123

Member
Licensed User
Longtime User
hi everyone , how i could do everything i write in edittext send it by mail , i test with this but dont work
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

Dim SMTP As SMTP
End Sub
Sub Globals
    'These variables can only be accessed from this module.
  Dim StatusSend1 As String
  Dim SMTP As SMTP
  StatusSend1=""
    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("3")
If FirstTime Then
SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "1234", "SMTP")
SMTP.UseSSL = True 'Esta linea la ponemos ya que Gmail requiere SSL
SMTP.To.Add("[email protected]")
SMTP.Subject = ("subject")
SMTP.Body = (EditText1.text)
End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub EnviarEMail1
  End Sub


Sub SMTP_MessageSent(Success As Boolean)
  If Success=True Then StatusSend1="SI enviado"
  If Success=False Then StatusSend1="NO Enviado"
  Log(StatusSend1)
End Sub

Sub Button1_Click
SMTP.Send
End Sub
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I looked at my code that is working and I have

SMTP.HtmlBody = True

I don't know if this is your problem...

Also you have SMTP declared in both process globals and globals
you only need it in globals
 
Upvote 0

piero123

Member
Licensed User
Longtime User
i put SMTP.HtmlBody = True , and dont work , i write some text in editext1 and i send to my email and the bodymail is empy , this is my code
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim SMTP As SMTP
End Sub
Sub Globals
    'These variables can only be accessed from this module.
  Dim StatusSend1 As String
    StatusSend1=""
    Dim  EditText1 As EditText
    Dim EditText2 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("3")
  If FirstTime Then
SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "1234", "SMTP")
SMTP.UseSSL = True 'Esta linea la ponemos ya que Gmail requiere SSL
SMTP.To.Add("[email protected]")
SMTP.Subject = ("hola")
SMTP.Body = EditText1.Text
SMTP.HtmlBody = True
End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub EnviarEMail1
  End Sub


Sub SMTP_MessageSent(Success As Boolean)
  If Success=True Then StatusSend1="SI enviado"
  If Success=False Then StatusSend1="NO Enviado"
  Log(StatusSend1)
End Sub

Sub Button1_Click
SMTP.Send

End Sub
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Your code is working. I think you have a problem with your gmail account.
I used your same code and put in my gmail account information and it worked fine.

B4X:
    SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "PASSWORD", "SMTP")
    SMTP.UseSSL = True 'Esta linea la ponemos ya que Gmail requiere SSL
    SMTP.To.Add("[email protected]")
    SMTP.Subject = ("hola")
    SMTP.Body = "body"
    SMTP.HtmlBody = True
  
    SMTP.Send
 
Upvote 0

piero123

Member
Licensed User
Longtime User
yeah is working but the
B4X:
SMTP.Body = EditText1.Text
dont work , i write some in editext1 and i send to my email and the body is empy :/
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As it stands, the SMTP.body is being set up before you can enter anything into EditText1. Try moving the

B4X:
SMTP.Body = EditText1.Text

to

B4X:
Sub Button1_Click
SMTP.Body = EditText1.Text
SMTP.Send

End Sub
 
  • Like
Reactions: eps
Upvote 0
Top