Skip to main content

Send email through Android application

Hi friends,In this tutorial I'm going to talk about how to send mail through android application .
So now have a look on the layout part:-
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
       android:background="@drawable/background"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:id="@+id/emailaddress"
        android:text="Email Address"
        android:textStyle="bold">
        </TextView>
   
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:width="250dip"
            android:hint="email address"
            android:id="@+id/address">
        </EditText>
   
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Subject"
            android:textStyle="bold">
        </TextView>
   
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:width="250dip"
            android:hint="Subject"
            android:id="@+id/subject">
        </EditText>
   
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your Message"
            android:textStyle="bold">
        </TextView>
    <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:lines="5"
            android:hint="Type message here!!"
            android:id="@+id/message">
        </EditText>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/send"
            android:text="Send Email"
            android:width="150dip">
        </Button>
</LinearLayout>
Now implement our code like this:
 MailSenderActivity.java
package com.dilip.mailsender;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;









public class MailSenderActivity extends Activity {



private Button clickBtn;
EditText address;
EditText subject;
EditText message;



@Override



public void onCreate(Bundle savedInstanceState) {



super.onCreate(savedInstanceState);



setContentView(R.layout.main);



clickBtn = (Button) findViewById(R.id.send);
address=(EditText)findViewById(R.id.address);
subject=(EditText)findViewById(R.id.subject);
message=(EditText)findViewById(R.id.message);
clickBtn.setText("Send email");



clickBtn.setOnClickListener(new OnClickListener() {



public void onClick(View v) {



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



//String[] recipients = new String[]{"androiddilip78@gmail.com", "",};



emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address.getText().toString());



emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());



emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message.getText().toString());



emailIntent.setType("text/plain");



startActivity(Intent.createChooser(emailIntent, "Send mail..."));



finish();



}



});



}



}



Our manifest should like this:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dilip.mailsender"
    android:versionCode="1"
    android:versionName="1.0" >



    <uses-sdk android:minSdkVersion="8" />



    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MailSenderActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />



                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
<!-- <uses-permission android:name="android.permission.INTERNET"></uses-permission> -->
</manifest>
This code will work fine but it doesn't work on emulator.
And finally our output looks like this...


Comments

Post a Comment

Popular posts from this blog

Android O New Features Overview

This post assumes, you are an experienced developer who wants to get started with the latest version of Android. Android O is not a huge update to the OS and application framework like M but it still has many useful features for both developer and an user. Android O has focus on below areas. Notification redesigned Picture-in-Picture(PIP)  Visual adaption for different devices  Battery life improved Setting app reorganized Notification redesigned: Android O notification changes includes more easy and manageable way to manager your notification behavior and settings. It includes: Notification Channel: Notification channel allows you to create user customizable channel for each type of notification you wanna display. A single application can have multiple channel, a separate channel for each type of notification you wanna display. Having said this, you can create s separate channel for audio & image notification. User can disable specific notification channe...

Display News and Videos through RSS and Display it in Listview

Hi friends , In this tutorial ,i'm going to describe about how to fetch data from rss feed.Here i had also problem ,when i was developing my recent project.I had also faced  many problem and at last i developed my best project. Here is the code that describe how to fetch news headline from rss This class describes how to parse XML data: import java.net.URL; import java.util.ArrayList; import org.xmlpull.v1.XmlPullParser; import android.content.res.XmlResourceParser; import android.util.Log; import android.util.Xml; public class XmlFeedParser {         //Feed Parsing Method     public ArrayList<Implement> parse(String url) {                 //Array of Episode Objects         ArrayList<Implement> episodes = null;          ...

Display video from specific folder with rounded shape thumbnail

Hi friends ,This is complete post, about how to display video form specific folder and display it with rounded shape and play it on click event. For Rounded shape I have used custom ImageView. Now have a look on code part. main.xml <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/gridView1"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:columnWidth="100dp"     android:gravity="center"     android:numColumns="auto_fit"     android:stretchMode="columnWidth" > </GridView> gridlayout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layo...