簡體   English   中英

從android應用發送電子郵件,指定發件人的電子郵件

[英]Sending email from android app specifying sender's email

我正在嘗試從我的android應用發送電子郵件。 此代碼對我來說很好

public void sendEmail(View v)
{
    StringBuilder msgBody = new StringBuilder();
    msgBody.append("name ").append("me").append("\n");
    msgBody.append("name ").append("you").append("\n");

    Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
    intent.putExtra(Intent.EXTRA_TEXT, " "+ msgBody.toString());
    intent.setData(Uri.parse("mailto:user@hotmail.com")); // or just "mailto:" for blank
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
    startActivity(intent);
}

使用此代碼,我可以指定接待人的電子郵件。 但是,我還需要指定發件人電子郵件。

有什么幫助嗎? 提前致謝

您無法指定發件人的電子郵件,因為用戶可能沒有該電子郵件。 您只能指定用戶應將其發送給誰,建議的消息和主題。

例如,如果我的電子郵件為example1@gmail.com,但是您希望我將電子郵件作為example@gmail.com發送,則將出現錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM