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.
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!
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.
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
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 :