.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

Send Email Via Gmail with Java Mail API in Android

1 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

Hi Guys!

Today I am sharing the code to send the email via gmail to any gmail user without interfere of any application with help of java mail API.
The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications.
In our application we are going to use following things from JavaMail API:
  • Multipart class: - it allow to device message into multipart so that long message can be sent easily.
  • Session: - in order to send mail we need to create session between hosts.
  • InternetAddress : it contains address , simply maid ID (example: abc@gmail.com).
For use of this you need to download the some jar file from Here.
1.  additional.jar
2. mail.jar
3. activation.jar

Download these jar file and make a java build path with your project.

Lets Start the coding to make a android project.

activity_main.xml















MainActivity.java

package com.sunil.sendmail;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.sunil.sendmail.R;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{

Session session=null;
ProgressDialog pdialog=null;
Context context=null;
EditText reciept=null;
EditText sub=null;
EditText msg=null;
String recpient=null;
String subject=null;
String textmessage=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=this;
Button login = (Button) findViewById(R.id.mBtnSubmit);
reciept=(EditText)findViewById(R.id.editText_to);
sub = (EditText) findViewById(R.id.editText_sub);
msg = (EditText) findViewById(R.id.editText_text);


login.setOnClickListener(this);


}

@Override
public void onClick(View v) {

recpient= reciept.getText().toString();
subject= sub.getText().toString();
textmessage= msg.getText().toString();

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Your Gmail-ID", "Your Gmail_password");
}
});
pdialog = ProgressDialog.show(context, "", "Sending Mail...",true);
RetreiveFeedTask task= new RetreiveFeedTask();
task.execute();
}


class RetreiveFeedTask extends AsyncTask {


protected String doInBackground(String... urls) {
try {

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("
Your Gmail-ID"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recpient));
message.setSubject(subject);
message.setContent(textmessage, "text/html; charset=utf-8");

Transport.send(message);


}
catch (MessagingException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();

}
return null;
}

protected void onPostExecute(String feed) {
pdialog.dismiss();
reciept.setText("");
msg.setText("");
sub.setText("");
Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();

}
}


}

Add the INTERNET permission in the AndroidManifest file .
  <uses-permission android:name="android.permission.INTERNET"/>

You can download the source code Send Mail.

Cheers Guys!

Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel Send Email Via Gmail with Java Mail API in Android, Diterbitkan oleh scodeaplikasi pada Selasa, 30 Juli 2013. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to