Sub Process_Globals
Dim SMTP As SMTP
End Sub
Sub Globals
Dim btnSendEmail As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout") ' Assuming you have a button called btnSendEmail in your layout
' Initialize the SMTP object
SMTP.Initialize("smtp.gmail.com", 587, "your-email@gmail.com", "your-app-specific-password", "SMTP")
SMTP.StartTLSMode = True ' Enable TLS encryption
SMTP.UseSSL = True ' Enable SSL encryption
SMTP.AuthMethod = SMTP.AUTH_LOGIN
End Sub
Sub btnSendEmail_Click
' Set the details of the email
SMTP.To.Add("recipient@example.com") ' Recipient's email address
SMTP.Subject = "Test Email from B4A"
SMTP.Body = "This is a test email sent from B4A using Gmail's SMTP server."
SMTP.MailFrom = "your-email@gmail.com"
SMTP.AddAttachment(File.DirRootExternal, "testfile.txt") ' Add an attachment (optional)
' Send the email
SMTP.Send
End Sub
Sub SMTP_MessageSent(Success As Boolean)
If Success Then
ToastMessageShow("Email sent successfully!", False)
Else
ToastMessageShow("Error sending email: " & LastException.Message, True)
End If
End Sub