Android Question Send email directly (without user intervention) ?

ComposerB4A

Member
Licensed User
Longtime User
Hello to all, i search send directly a email (without user intervention), i try:

SMTP.Initialize("smtp.mail.yahoo.com", 465, "[email protected]","clave123","SMTP")
SMTP.To.Add("[email protected]")
SMTP.Subject = "hola"
SMTP.Body = "Hola"
SMTP.Send
...
MessageSent event not run

the question, ¿because not send the email? o_O
 

ComposerB4A

Member
Licensed User
Longtime User
Thanks You, i apply and works :)
SMTP.Initialize("smtp.mail.yahoo.com", 465, "[email protected]","clave123","SMTP")
SMTP.UseSSL = True
SMTP.To.Add("[email protected]")
SMTP.Subject = "hola"
SMTP.Body = "Hola"
SMTP.Send
...
Sub SMTP_MessageSent(Success As Boolean)
...
ButMessageSent event not run o_O

But the event "MessageSent" not work, because i run the App, not run event "MessageSent", the user "not know" that the email "was send", but after of minutes, the email appear in the adressee(r) ¿exist some code for know that sending was correct (maybe using a service)?
 
Last edited:
Upvote 0

ComposerB4A

Member
Licensed User
Longtime User
Hi, set only one once initializing SMTP object:

B4X:
Sub Globals
    'These variables can only be accessed from this module.
  Dim StatusSend1 As String
  Dim SMTP As SMTP
  StatusSend1=""
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")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub EnviarEMail1
  SMTP.Initialize("smtp.mail.yahoo.com", 465, "[email protected]","clave123","SMTP")
  SMTP.UseSSL = True
  SMTP.To.Add("[email protected]")
  SMTP.Subject = "hola2"
  SMTP.Body = "Hola2"
  SMTP.Send
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
EnviarEMail1
End Sub
(fix: code original, in code tags)
 
Last edited:
Upvote 0

piero123

Member
Licensed User
Longtime User
i have a error i initialize SMTP In activity create but i have error


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub
Sub Globals
    'These variables can only be accessed from this module.
  Dim StatusSend1 As String
  Dim SMTP As SMTP
  StatusSend1=""
    Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
  SMTP.Initialize
 
    Activity.LoadLayout("3")


End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub EnviarEMail1
SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "awdawd", "SMTP")
SMTP.UseSSL = True
SMTP.To.Add("[email protected]")
SMTP.Subject = "Asunto del Email"
SMTP.Body = "Cuerpo del mensaje."
SMTP.AddAttachment(File.DirRootExternal, "elarchivoquequeremosadjuntar")
SMTP.Send
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
EnviarEMail1
End Sub

[ /code ]
 
Upvote 0

pesquera

Active Member
Licensed User
Longtime User
I need SMTP on a service instead of an activity.. how/where should I initialize it?
 
Last edited:
Upvote 0
Top