To use JavaMail API for sending mails in Android without using the default built-in App

0 votes

I am trying to send mail through application in Android .

By using this:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

will solve my work. But, I want to send my mails by single button click.

Jun 6, 2018 in Java by prasad
• 160 points
1,458 views

1 answer to this question.

0 votes

ADD 3 jars found in the following link to your Android Project

mail.jar
activation.jar
additional.jar

And don't forget to add this line in your manifest:

<uses-permission android:name="android.permission.INTERNET" />

Check with the sample project:

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MailSenderActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button send = (Button) this.findViewById(R.id.send);
        send.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {   
                    GMailSender sender = new GMailSender("username@gmail.com", "password");
                    sender.sendMail("This is Subject",   
                            "This is Body",   
                            "user@gmail.com",   
                            "user@yahoo.com");   
                } catch (Exception e) {   
                    Log.e("SendMail", e.getMessage(), e);   
                } 

            }
        });

    }
}
answered Jun 6, 2018 by sridhar
• 160 points

Related Questions In Java

0 votes
1 answer

Sending Email in Android using JavaMail API without using the default/built-in app

Send e-mail in Android using the JavaMail ...READ MORE

answered Dec 4, 2018 in Java by Daisy
• 8,140 points
3,466 views
0 votes
1 answer

How to call a method after a delay in Android using Java?

final Handler handler = new Handler(); handler.postDelayed(new Runnable() ...READ MORE

answered Jun 11, 2018 in Java by Akrati
• 3,190 points
5,343 views
+1 vote
1 answer

How to tell the Maven to use the latest version of dependency in Java?

If you always want to use the ...READ MORE

answered Jun 26, 2018 in Java by Sushmita
• 6,920 points
15,382 views
0 votes
1 answer

What are the Foreign key constraints in Android using SQLite

You can use, Foreign key constraints with ...READ MORE

answered Aug 24, 2018 in Java by geek.erkami
• 2,680 points
1,760 views
+2 votes
1 answer

How do I ask the Selenium-WebDriver to wait for few seconds in Java?

There are two ways to wait: explicit ...READ MORE

answered Dec 19, 2018 in Java by Daisy
• 8,140 points

edited Dec 19, 2018 by Daisy 957 views
0 votes
1 answer

How to specify the certificate to use for authenticating the server to client?

You can try the command given below. System.setProperty("javax.net ...READ MORE

answered Jan 2, 2019 in Java by Daisy
• 8,140 points
1,291 views
+2 votes
1 answer

please someone tell the code to launch an instance in digital ocean using java

In order to create a digital ocean ...READ MORE

answered Jan 14, 2020 in Java by Sirajul
• 59,230 points
1,285 views
0 votes
1 answer

how to read csv file form sftp connection and store into string object in java code and convert into json.....post it using rest api

Hey, @Pooja, Before starting with anything you should ...READ MORE

answered May 13, 2020 in Java by Roshni
• 10,480 points
3,832 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP