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
500 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,050 points
554 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,150 points
2,019 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,880 points
2,149 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,640 points
90 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,050 points

edited Dec 19, 2018 by Daisy 67 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 in Java by Daisy
• 8,050 points
31 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
603 views
0 votes
1 answer

How to print java array in the simplest way?

String[] arr = new String[] {"John", "Mary", ...READ MORE

answered Apr 17, 2018 in Java by sophia
• 1,400 points
88 views