App inventor 2 mail component
In App Inventor 2, the Mail
component is used to send emails from your app. Here are some key features and properties of the Mail
component:
Properties:
To
: The recipient's email address.Subject
: The subject line of the email.Body
: The body of the email.From
: The sender's email address (default is the app's email address).CC
: The email address of the carbon copy recipient (optional).BCC
: The email address of the blind carbon copy recipient (optional).
Methods:
Send()
: Sends the email.Cancel()
: Cancels the email sending process.
Events:
OnSendComplete()
: Triggered when the email is sent successfully.OnSendError()
: Triggered when an error occurs while sending the email.
Usage:
To use the Mail
component in your App Inventor 2 app, follow these steps:
- Drag and drop the
Mail
component from the Palette onto your app's screen. - Set the
To
,Subject
, andBody
properties using the Designer or the Blocks Editor. - Use the
Send()
method to send the email when the user clicks a button or performs some other action. - Handle the
OnSendComplete()
andOnSendError()
events to respond to the outcome of the email sending process.
Here's an example of how you might use the Mail
component in your app:
// Send an email when the user clicks a button
Button1.Click :: SendEmail
// Define the email properties
Mail1.To = "[email protected]"
Mail1.Subject = "Hello from my app!"
Mail1.Body = "This is a test email sent from my app."
// Send the email
Mail1.Send()
// Handle the OnSendComplete event
Mail1.OnSendComplete :: ShowToast("Email sent successfully!")
// Handle the OnSendError event
Mail1.OnSendError :: ShowToast("Error sending email: " + Mail1.Error)
Note that the Mail
component requires a valid email account to send emails. You can configure the email account settings in the App Inventor 2 settings menu.