Automatic mail sent on button click android

To send an automatic email on a button click in an Android app, you can use the JavaMail API and the Android Email Intent. Here's a step-by-step guide:

Step 1: Add the JavaMail API to your project

Step 2: Create a button and a layout

``` **Step 3: Write the code to send the email**

import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties;

public class MainActivity extends Activity {

private Button sendEmailButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    sendEmailButton = findViewById(R.id.send_email_button);
    sendEmailButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendEmail();
        }
    });
}

private void sendEmail() {
    Properties props = new Properties();
    props.put("mail.smtp.host", "your-smtp-host");
    props.put("mail.smtp.port", "your-smtp-port");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("your-email", "your-password");
        }
    });

    try {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("your-email"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient-email"));
        message.setSubject("Test Email");
        message.setText("This is a test email");

        Transport.send(message);
        Toast.makeText(this, "Email sent successfully!", Toast.LENGTH_SHORT).show();
    } catch (MessagingException e) {
        Toast.makeText(this, "Error sending email: " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

}


* Replace `your-smtp-host`, `your-smtp-port`, `your-email`, and `your-password` with your actual SMTP host, port, email address, and password.
* Replace `recipient-email` with the email address of the recipient.

**Step 4: Run the app**

* Run the app on an emulator or a physical device.
* Click the "Send Email" button to send an automatic email.

Note: Make sure to replace the placeholders with your actual values and test the email sending functionality before deploying the app.