Send a Mail in Android programmatically
Selasa, 03 September 2013
0
komentar
1.Create a Class Mail_Utils
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;
public class Mail_Utils {
/**
* @param address
* @param subject
* @param emailbody
* @param activity
* Function to send a e-mail.
*/
public static void sendEmail(String address,String subject,String emailbody,Activity activity){
if(!address.trim().equalsIgnoreCase("")){
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailbody);
activity.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
else{
Toast.makeText(activity, "Please enter an email address..", Toast.LENGTH_LONG).show();
}
}
}
2.Use this in your MainActivity
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mail_Utils.sendEmail("nikhil.v@xyz.com", "Test", "Hiii",MainActivity.this);
}
}
Now, are able to Send a Mail in Android programmatically.
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;
public class Mail_Utils {
/**
* @param address
* @param subject
* @param emailbody
* @param activity
* Function to send a e-mail.
*/
public static void sendEmail(String address,String subject,String emailbody,Activity activity){
if(!address.trim().equalsIgnoreCase("")){
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailbody);
activity.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
else{
Toast.makeText(activity, "Please enter an email address..", Toast.LENGTH_LONG).show();
}
}
}
2.Use this in your MainActivity
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mail_Utils.sendEmail("nikhil.v@xyz.com", "Test", "Hiii",MainActivity.this);
}
}
Now, are able to Send a Mail in Android programmatically.
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Send a Mail in Android programmatically
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://samsung-galaxy-s2r.blogspot.com/2013/09/send-mail-in-android-programmatically.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar