sirushti
sirushti

Reputation: 137

How to i create a button on my website which opens email client on mobile

Hi am trying to create a button on my website called "Open My Inbox". ( Which user can quickly open their email inbox to verify the email received for account verification) When user clicking on that button it should show email apps available on the mobile such as ( gmail, yahoo or default)

Am aware of mailto: links, But is there any solution to open the default or other email application

Application Screen

Upvotes: 0

Views: 1914

Answers (3)

Syed
Syed

Reputation: 704

Take your pick from below. Trick is in mailto available ever since I know so. What will happen is it will trigger an intent or some times called native intent.

Example: on desktop if there is email client that is configured in the system it will launch that. On windows browser sends email intent to system who then checks registry, if there is some software hooked on that intent it will launch and populate the data to software. If there isn't it will either throw odd error or simply stay silent.

Same is on mobile it will go through the same if there is any app hooked it will launch it. in most cases it would route it self to one set as default, tbh there is always a default app for email on mobiles.

Example of intent. if you have Instagram or facebook app running. go to google search for a user name then click on result to view, pop-up gets triggered open in facebook/Instagram or keep using browser. That is intent working in the background.

Other than triggering this feature you do not have much control over the whole process.

<button style="background-color: blue; color:white;" onclick="location.href='[email protected]';">Send Email</button>

<button  style="background-color: blue;"><a href="mailto:[email protected]"  style=" color:white;">Send Email</a></button>

<a href="mailto:[email protected]" style="display:inline-block; height:20px;width:80px;background-color: blue; color:white;">Send Email</a>

further reading

web intent

android intent

Upvotes: 2

Ole Pannier
Ole Pannier

Reputation: 3673

In your MainActivity.java define a Button and Intent for the required services like that:

package com.example.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = findViewById(R.id.idbtn);
    }
    public void btnClick(View v){

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setData(Uri.parse("email"));
        String[] s={"[email protected]","[email protected]"};
        i.putExtra(Intent.EXTRA_EMAIL,s);
        i.putExtra(Intent.EXTRA_SUBJECT, "This is a Subject");
        i.putExtra(Intent.EXTRA_TEXT,"Hi, This is the Email Body");
        i.setType("message/rfc822");
        Intent chooser = Intent.createChooser(i,"Launch Email");
        startActivity(chooser);
    }
}

After that you are going to set your Button in the activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity"
    android:orientation="horizontal">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/idbtn"
        android:onClick="btnClick"
        android:text="Launch Email"
        android:layout_gravity="center"/>
</LinearLayout>

Define the permission.INTERNET in your AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application

The services will be intent by clicking that launch Email Button like that:

Result

Upvotes: 1

Dr M L M J
Dr M L M J

Reputation: 2397

Any Websites can not detect in advance if website users have email client on their laptop, computers or devices. so the mailto will try to run even if the user doesn’t have an email application.

creating a contact us page with a contact email, phone or mobile number and name with help of php or asp.net is better option for users to contact and communicate with us.

for more details about mailto and contact form comparison, pkease visit -

this will help you for mobile related query...

https://css-tricks.com/all-about-mailto-links/

and below links are for more information abouut mailto and contact form....

https://www.google.com/amp/s/www.campaignmonitor.com/blog/email-marketing/should-i-use-a-mailto-or-link-to-a-contact-form/m/

and

https://www.uncinc.nl/nl/articles/dealing-mailto-links-if-no-mail-client-available

Upvotes: 2

Related Questions