Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Breaking News

How to Send Email in Android app using Intent | Contact us Form in Android app

How to Send Email in Android app using Intent | Contact us Form in Android app


In this post, we create a Contact Us form in the Android App. We create 2 Edit text and a Send button to send email in the android app.

We get a subject and message from our app and pass it to the email client.

Create 2 EditText and a Button in activity_main.xml

activity_main.xml
 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:orientation="vertical"  
   tools:context=".Contact_us">  
   <EditText  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:hint="contact@harpreetstudio.com"  
     android:enabled="false"  
     android:padding="10dp"  
     />  
   <EditText  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:hint="Subject"  
     android:id="@+id/email_subject"  
     android:padding="10dp"  
     />  
   <EditText  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:hint="Message"  
     android:maxLines="4"  
     android:padding="10dp"  
     android:id="@+id/email_message"  
     />  
   <Button  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:text="Send"  
     android:id="@+id/email_send"/>  
 </LinearLayout>  

Now, we create an Intent to send values to Email client in you Android.

MainActivity.java
 package studio.harpreet.sampleproject;  
 import androidx.appcompat.app.AppCompatActivity;  
 import android.content.Intent;  
 import android.net.Uri;  
 import android.os.Bundle;  
 import android.view.View;  
 import android.widget.Button;  
 import android.widget.EditText;  
 import android.widget.Toast;  
 public class Contact_us extends AppCompatActivity {  
     EditText et_subject,et_message;  
     Button btn;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_contact_us);  
     et_subject = findViewById(R.id.email_subject);  
     et_message = findViewById(R.id.email_message);  
     btn = findViewById(R.id.email_send);  
     btn.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View v) {  
         String subject = et_subject.getText().toString().trim();  
         String message = et_message.getText().toString().trim();  
         String email = "contact@harpreetstudio.com";  
         if(subject.isEmpty())  
         {  
           Toast.makeText(Contact_us.this, "Please add Subject", Toast.LENGTH_SHORT).show();  
         }  
         else if(message.isEmpty())  
         {  
           Toast.makeText(Contact_us.this, "Please add some Message", Toast.LENGTH_SHORT).show();  
         }  
         else  
         {  
           String mail = "mailto:" + email +  
               "?&subject=" + Uri.encode(subject) +  
               "&body=" + Uri.encode(message);  
           Intent intent = new Intent(Intent.ACTION_SENDTO);  
           intent.setData(Uri.parse(mail));  
           try {  
             startActivity(Intent.createChooser(intent,"Send Email.."));  
           }  
           catch (Exception e)  
           {  
             Toast.makeText(Contact_us.this, "Exception: "+e.getMessage(), Toast.LENGTH_SHORT).show();  
           }  
         }  
       }  
     });  
   }  
 }  

 
Follow us for more posts like this, 
Subscribe to Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

20 comments:

  1. Android App Maker makes it easy to create an app of your own. Cyberflix APK

    ReplyDelete
  2. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks email extractor 9.0

    ReplyDelete
  3. I have read your article couple of times because your views are on my own for the most part. It is great content for every reader. how to send customized email from gmail

    ReplyDelete
  4. A great content material as well as great layout. Your website deserves all of the positive feedback it’s been getting. I will be back soon for further quality contents. one funnel away challenge

    ReplyDelete
  5. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. spacedesk

    ReplyDelete
  6. Deciding on a brand name is one of the common mistakes of startup companies. Having names that is thoroughly thought off is an edge that can lead your company to success. Email Extractor

    ReplyDelete
  7. Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long. I will need this post to total my assignment in the college, and it has exact same topic together with your write-up. Thanks, good share. https://satta-king.center/

    ReplyDelete
  8. The seller stamps his name in the clear space under "Request Form" and mails them to forthcoming clients. At the point when he gets requests (and he will in the event that he mails them consistently), he keeps his bonus, which is generally about half.

    ReplyDelete
  9. This is important, though it's necessary to help you head over to it weblink: LinkedIn Profile Scraper

    ReplyDelete
  10. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Zendable

    ReplyDelete
  11. Thank you so much for ding the impressive job here, everyone will surely like your post. best remote access tools

    ReplyDelete
  12. iPhone Facebook app development has changed the scenario of the smart phone. The social networking site has been remodeled by the iPhone Facebook apps developer to give you all the applications with their complete view and full functionality. spotify++

    ReplyDelete
  13. Shockingly, relatively few clients comprehend or set aside effort to check what authorizations they award. AFK Arena Codes

    ReplyDelete
  14. However these applications were at that point a piece of many advanced cells that preceded Android, these were costly sufficient that not every person had the option to manage the cost of them. With the presentation of Android controlled PDAs and tablets on the lookout, this whole scope of very good quality games just as applications turned out to be more available to the normal masses. walkie talkie long range

    ReplyDelete
  15. In a few short sentences, you start your game producer career in an old garage. You hire people to help you on your adventure. On my first try I went bankrupt and on my second try I became a millionaire so the game is easy to learn. You just need to check and use every feature you see. https://www.buyyoutubeviewsindia.in/youtube-marketing/

    ReplyDelete
  16. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. android programming wallpapers

    ReplyDelete
  17. Thanks for sharing this valuable content. In my view, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before. what is iot hidden menu

    ReplyDelete
  18. I really loved reading your blog. It was very well authored and easy to understand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he enjoyed it as well!
    english stories

    ReplyDelete
  19. Solid Email Subject Lines
    Solid headlines are the mystery ingredient of email advertising. It's the primary thing individuals see when they open their inbox-an initial feeling of your substance. gmx login

    ReplyDelete
  20. This can assist with setting up that you are the business to go to for a specific item or administration. gmx net

    ReplyDelete