How to send emails from my Android application?

前端 未结 21 2332
春和景丽
春和景丽 2020-11-22 00:38

I am developing an application in Android. I don\'t know how to send an email from the application?

21条回答
  •  孤独总比滥情好
    2020-11-22 01:03

    Try this:

    String mailto = "mailto:bob@example.org" +
        "?cc=" + "alice@example.com" +
        "&subject=" + Uri.encode(subject) +
        "&body=" + Uri.encode(bodyText);
    
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse(mailto));
    
    try {
        startActivity(emailIntent);
    } catch (ActivityNotFoundException e) {
        //TODO: Handle case where no email app is available
    }
    

    The above code will open the users favourite email client prefilled with the email ready to send.

    Source

提交回复
热议问题