---
title: "how to send email from own mail server instead of gmail server in android without user interaction"  
description: "how to send email from own mail server instead of gmail server in android without user interaction"  
author: "Shubhasish Routray"  
published: 2017-09-19  
updated: 2023-07-02  
canonical: https://www.mindstick.com/forum/34346/how-to-send-email-from-own-mail-server-instead-of-gmail-server-in-android-without-user-interaction  
category: "android apps"  
tags: ["android"]  
reading_time: 3 minutes  

---

# how to send email from own mail server instead of gmail server in android without user interaction

please anybody can tell how to [send mail](https://www.mindstick.com/articles/1502/how-to-send-mail-in-node-js) in [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [app development](https://www.mindstick.com/services/mobile-app-development) using own [mail server](https://answers.mindstick.com/qa/95222/how-do-i-find-my-mail-server-in-outlook-365) [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) [gmail](https://www.mindstick.com/articles/157262/why-to-go-with-the-gmail-signup-procedure) server .\
i am using 3 [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) GmailSender.java, JSSEProvider.java, MainActivity.java\
thank you.

## Replies

### Reply by Aryan Kumar

Sure, here is how to send an email from your own mail [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) or Gmail server in Android without user interaction:

1. You need to create a Java class that extends the `AsyncTask` class. This class will be responsible for sending the email.
2. In the `doInBackground()` method of the class, you need to create an instance of the `Mail` class. The `Mail` class is used to send emails.
3. You need to set the properties of the `Mail` object, such as the sender, recipients, subject, and body of the email.
4. You need to call the `send()` method of the `Mail` object to send the email.
5. You need to override the `onPostExecute()` method of the class. In this method, you can handle the result of sending the email.

Here is an example of how you can send an email from your own mail server or Gmail server in Android without user interaction:

Code snippet

```plaintext
public class SendEmailTask extends AsyncTask<Void, Void, Void> {

    private String sender;
    private String[] recipients;
    private String subject;
    private String body;

    public SendEmailTask(String sender, String[] recipients, String subject, String body) {
        this.sender = sender;
        this.recipients = recipients;
        this.subject = subject;
        this.body = body;
    }

    @Override
    protected Void doInBackground(Void... voids) {
        // Create an instance of the Mail class
        Mail mail = new Mail();

        // Set the properties of the Mail object
        mail.setSender(sender);
        mail.setRecipients(recipients);
        mail.setSubject(subject);
        mail.setBody(body);

        // Send the email
        mail.send();

        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        // Handle the result of sending the email
    }
}
```

To use this code, you would need to create an instance of the `SendEmailTask` class and call the `execute()` method. For example, you could call the method in your app's `onCreate()` method.

Here is an example of how you could call the `execute()` method in your app's `onCreate()` method:

Code snippet

```plaintext
public void onCreate() {
    super.onCreate();

    // Get the sender
    String sender = "sender@example.com";

    // Get the recipients
    String[] recipients = {"recipient1@example.com", "recipient2@example.com"};

    // Get the subject
    String subject = "This is an email";

    // Get the body
    String body = "This is the body of the email";

    // Create an instance of the SendEmailTask class
    SendEmailTask sendEmailTask = new SendEmailTask(sender, recipients, subject, body);

    // Send the email
    sendEmailTask.execute();
}
```

### Reply by Florence Eliza

Post is removed by the Admin.


---

Original Source: https://www.mindstick.com/forum/34346/how-to-send-email-from-own-mail-server-instead-of-gmail-server-in-android-without-user-interaction

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
