How to send email on Android systems and what are the ways?
12 minute(s) read
|
Published on: Jul 31, 2021
Updated on: Dec 14, 2021
|
In Android systems, you can send emails. There are many ways to do this that can be configured to send emails to different users in Android systems. As you learned in the previous sections, you know that Android Intent is an object used to pursue a goal in such a way that it can send a message from one component to another. Therefore, it can be said that one of the most common ways to send an email on Android systems is to use the Android Intent object.
Email operation using Intent Object.
To send an email on Android systems, you must use Intent Object so that you can finally install an email user on your device and use it to send the email.
The code below shows how to create and use Intent Objects.
After entering the codes to create the user installed in the system to send the email, I must also specify mail.
In this section, the data type must be text / plain, specified using the set Type () method. Like the codes listed below:
After specifying the type of data sent in sending emails, there is another feature in Android systems that we can use to insert additional attachments. In this case, when sending an email, in addition to SUBJECT, CC, TEXT attachments, it is possible to create and add other attachments. We can add those attachments and use their capabilities when sending an email.
EXTRA_BCC Attachment:
This attachment stores strings of email addresses that must be duplicated.
EXTRA_CC Attachment:
This attachment stores the strings of email addresses that must be copied.
EXTRA_EMAIL Attachment:
This attachment stores the strings of email addresses that must be delivered to them.
EXTRA_HTML_TEXT Attachment:
This attachment is a fixed string related to Intent and can be used using ACTION_SEND and provides a convenient option for EXTRA_TEXT when formatting HTML text.
EXTRA_SUBJECT Attachment:
This attachment is a fixed string that can be used to hold the subject line.
Attachment EXTRA_TEXT:
This attachment is also a fixed CharSequence and is also associated with Intent. This attachment can be used using ACTION_SEND to prepare literal data for submission.
EXTRA_TITLE Attachment:
This attachment also provides the user with a CharSequence dialog title and can also be used using ACTION_CHOOSER.
We will give you an example in the code below and tell you how to assign your data to Intent.
In this example, we show you how you can use the user who started the email so that you can finally send an email to your recipient users.
The requirements for being able to go through this example step by step with the tutorials are as follows:
A mobile device that has the latest version of Android OS. Install email user on your mobile device with the latest version of the operating system, such as Gmail or K9mail.
It is recommended that you pay attention to the following points, which are useful explanations, before you start working. The important points that you should consider in these steps are as follows:
1- We use Eclipse IDE to design an Android application.
2- We must choose a name for the designed program, which is selected in this part of the SendEmailDemo tutorial.
3- You must note that we create and name the created program inside the com. Example. sendemaildemo package.
4- Use SDK and Compile with the latest version so that you can finally use APIs with higher levels.
5- Modify and edit the src / MainActivity.java file.
6- Then, we must change the layout of the XML file to res/layout / activity_main.xml and add the code related to adding any required GUI to them.
7- We also change res/ values/strings.xml.
8- AndroidManifest.xml should be changed as follows.
9- The codes and contents that should be included in the main activity after the change are as follows
10- After inserting the contents and codes inserted in the above section, we will see the contents and codes that should be in the res/ layout / activity_main.xml section below.
11- The code and contents that should also be in the res/ values / strings.xml section are as follows:
12- In the AndroidManifest.xml file, the default contents that should be included are as follows:
13- After inserting the desired contents and codes in the relevant sections, we must run the program.
14- Run the SendEmailDemo program that we have created and put the contents inside them.
15- To run the program, we must open one of the project activities files from the Eclipse section.
16- After opening one of the program activities files in the toolbar, we must click on the Run icon.
17- Before running the program, a window will be displayed in which I must specify what we want the program to run on.
18- In this case, we must select our mobile device to run the program on it.
19- To have a list of all users installed on the email, we must click on Compose Email.
20- From this list, we must select a user to send the desired email to the person.
21- Finally, after completing and making all the changes to send the email, you must press send an email.
In addition to sending emails in Android systems, it is also possible to send SMS, and there are ways to do this.
The ways that can be used to send SMS on Android systems are as follows:
Send SMS using SMS Manager. Send SMS using internal Intents.
How to send SMS using SMS Manager?
Using this method and SMS Manager, it is possible to manage and control the SMS, and we can call this object to use it.
How to call and create this object using the static method is as follows:
You can send SMS to the number you want using the SMS Manager object and the sendDataMessage () method. Like the following:
Other important functions available in SMS Manager and can be used are as follows.
- ArrayList divideMessage (String text):
Using this method, the entire text of the message is divided into several sections, and none of the sections are the largest part of the message text. They are all divided into approximately equal sections.
- static SmsManager getDefault ():
This method can also be used to obtain default SmsManager instances.
- void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte [] data, PendingIntent sentIntent, PendingIntent deliveryIntent):
We use this method to send the SMS database to a specific application port.
- void sendMultipartTextMessage (String destinationAddress, String scAddress, ArrayList parts, ArrayList sentIntents, ArrayList deliveryIntents):
This method also sends a text that is divided into SMS.
- void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent):
This method also sends an SMS text.
To better understand this issue, we will give you an example so that you can understand and understand it more easily. In this example, we will easily show you how to use the SMS Manager object to send an SMS to a number.
The requirements for being able to go through this example step by step with the tutorials are as follows:
1- A mobile device that has the latest version of Android OS.
2- We use Eclipse IDE to create an Android application.
3- For the program we create, we must choose a name, the name chosen in this tutorial is SendSMSDemo.
4- Create, name, and save the program under the com.example.sendsmsdemo template and package.
5 - It should be noted that you must note that the Target SDK and Compile With that you are using are the latest versions so that you can finally use the high levels of the API.
6- Then, we must change the src / MainActivity.java file and enter the related code there.
7- We must change the layout of the XML file to res/ layout / activity_main.xml and add all the required GUI components.
8- Then, we create a simple GUI and a button to send SMS to finally receive the mobile number and the text of the sent message.
9- We must also change res/ values / strings.xml and enter the necessary contents in it.
10- Then, we must change the AndroidManifest.xml file as below.
The contents and code that should be changed and included in the whole file are as follows:
11- The codes and contents that should be in the res/layout / activity_main.xml section are as follows:
12- The code inserted in the res/values/strings.xml file section is used to create two new fixed numbers.
13- All the contents and default codes of AndroidManifest.xml section are as follows:
14- Then, we must run SendSMSDemo.
15- After inserting the desired contents and codes in the relevant sections, we must run the program.
16- Run the SendEmailDemo program that we have created and put the contents inside them.
17- To run the program, we must open one of the project activities files from the Eclipse section.
18- After opening one of the project activities files in the toolbar, we must click on the Run icon.
19- Before the program runs, a window is displayed in which we must specify what we want the program to run.
20- In this case, we must select our mobile device to run the program on it.
21- In this case, you can enter a desired mobile number in the box and send your desired SMS to that number.
22- After entering your desired number and text, you can send an SMS to the desired number by pressing the Send SMS button.
How to send an SMS using the internal Intent In this part of the tutorial, we also want to tell you about sending an SMS using the internal Intent method.
In this case, I must use an SMS user installed on the mobile device so that we can finally send the SMS to the desired number by using ACTION_VIEW.
The code below shows how to create an Intent with the ACTION_VIEW activity.
It should be noted that the Android system has internal support that can be used to support numbers and text messages. Like the following:
You can enter more than one phone number and separate them using a semicolon (;).
In the next section, we will give you an example to easily understand how to send SMS using the built-in Intent method.
The requirements for being able to go through this example step by step with the tutorials are as follows:
A mobile device that has the latest version of Android OS.
1- We use Eclipse IDE to be able to design an Android application.
2- We must choose the name for the designed program, which is the name selected in this part of the SendSMSDemo tutorial.
3- You must note that we create and name the created program inside the com. Example. sendsmsdemo package.
4- Use SDK and Compile with the latest version so that you can finally use APIs with higher levels.
5- Modify and edit the src / MainActivity.java file.
6- Then, we must change the layout of the XML file to res/layout / activity_main.xml and add the code related to adding any required GUI to them.
7- We also change res/ values / strings.xml.
8- AndroidManifest.xml should be changed as follows.
9- The codes and contents that should be included in the main activity after the change are as follows:
10- The contents that should be in the res/values/strings.xml section are as follows:
11- The default codes and contents of the AndroidManifest.xml file are as follows:
12- After inserting the desired contents and codes in the relevant sections, we must run the program.
13- Run the SendEmailDemo program that we have created and put the contents in them.
14- To be able to run the program, we must open one of the program activities files from the Eclipse section.
15- After opening one of the project activities files in the toolbar, we must click on the Run icon.
16- Before running the program, a window will be displayed in which I must specify what we want the program to run on.
20- In this case, we must select our mobile device as an option to run the program on it.
21- After presenting the changes, we can press the send SMS button to finally send our SMS to the desired number.
About our Android and iOS app development services