Introduction
In this article you will learn how to develop email applications for sending information from one mail to another in Android applications using Android Studio.
Requirements
If you want to develop the email application it should follow the below steps.
Step 1
Now, open Android studio and go to File and New and choose NewProject .
Step 2
Her, you will write the application name and click the next button.
Now, we can choose the application version, it is Target version and devices.
Step 3
Now choose to Activity (Blank Activity, Empty Activity) and click the Next button.
Here, you will write the Activity name and click the Finish button.
Step 4
Here, NewProject is open and you will go to design page (activity_main.xml) and you will build the design, it should follow the drag and drop method, it is the option (editText,Button).
Here,you will see the design page(Graphical user Interface).
Now,you will see the activity_main.xml code
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="xyz.rvconstructions.www.sendemailapp.MainActivity">
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:ems="10" android:id="@+id/editText" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" />
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:ems="10" android:id="@+id/editText2" android:layout_below="@+id/editText" android:layout_alignRight="@+id/editText" android:layout_alignEnd="@+id/editText" />
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:ems="10" android:id="@+id/editText3" android:layout_below="@+id/editText2" android:layout_alignRight="@+id/editText2" android:layout_alignEnd="@+id/editText2" />
- <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SEND MAIL" android:id="@+id/sendbttn" android:layout_centerVertical="true" android:layout_alignLeft="@+id/editText3" android:layout_alignStart="@+id/editText3" />
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Recipient" android:id="@+id/textView" android:layout_alignBottom="@+id/editText" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="subject" android:id="@+id/textView2" android:layout_alignBottom="@+id/editText2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Message Body" android:id="@+id/textView3" android:layout_alignBottom="@+id/editText3" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
Step 5
Now ,you will build on AndroidManifest.xml code.
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xyz.rvconstructions.www.sendemailapp">
- <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
- </activity>
- </application>
- </manifest>
Step 6
Now, you will go to MainActivity.java page and you will build the java code.
First of all you will declare the Header file.
- package xyz.rvconstructions.www.sendemailapp;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.net.Uri;
- import android.app.Activity;
- import android.content.Intent;
- import android.util.Log;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
Now, you will declare and get the reference in the button and perform the OnClickListener.
- Button startBtn = (Button) findViewById(R.id.sendbttn);
- startBtn.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- sendEmail();
- }
- });
Here, you will assign the method() of sendEmail().
- protected void sendEmail() {
- Log.i("Send email", "");
- String[] TO = {
- "[email protected]"
- };
- String[] CC = {
- "[email protected]"
- };
- Intent emailIntent = new Intent(Intent.ACTION_SEND);
- emailIntent.setData(Uri.parse("mailto:"));
- emailIntent.setType("text/plain");
- emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
- emailIntent.putExtra(Intent.EXTRA_CC, CC);
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
- emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
- try {
- startActivity(Intent.createChooser(emailIntent, "Send mail..."));
- finish();
- Log.i("Finished sending email...", "");
- } catch (android.content.ActivityNotFoundException ex) {
- Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
- }
- }
-
- if ('this_is' == /an_example/) {
- of_beautifier();
- } else {
- var a = b ? (c % d) : e[f];
- }
Step 7
Now ,you will run the application in emulator or devices.
Here,you will choose the emulator or devices
Step 8
Now, you will see the output.
Here, you will fill the data and you will click the SEND EMAIL button.
Now, you will choose one option -- Gmail.com(Email).
Here,you will see the To and From mail address and click the send option.
Now,you will see that mail send item.
Here,you will recipeint([email protected]) receive the inbox mail.
Summary
Hence, it is used to how to send the mail in one mail to another mail in Android applications using Android Studio.