简体   繁体   English

如何在不使用intent的情况下将背景中的电子邮件从android手机发送到我的电子邮件

[英]how to send email in background from the android phone to my email without using intent

how can i send email in code from my phone to my account without using the intent ?? 我如何在不使用意图的情况下将代码中的电子邮件从手机发送到我的帐户? i mean without getting the popup window that ask me witch application i want to use to send the email. 我的意思是没有得到要求我发送电子邮件的应用程序的弹出窗口。

this what i used using the intent. 这就是我使用意图的目的。

package com.example.emaildemo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    Button btnSendEmail;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnSendEmail = (Button) findViewById(R.id.btnSendEmail);        
        btnSendEmail.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {     
                String[] to = {"receiver@gmail.com"};   
                String[] cc = {"receiver.aoude@gmail.com"};           
                sendEmail(to, cc, "Hello", "Hello my friends!");
            }
        });
    }
     //---sends an SMS message to another device---
    private void sendEmail(String[] emailAddresses, String[] carbonCopies, 
    String subject, String message)
    {     
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setData(Uri.parse("mailto:")); 
        emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddresses);   
        emailIntent.putExtra(Intent.EXTRA_CC, carbonCopies);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, message);        
        emailIntent.setType("message/rfc822");   
        emailIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(Intent.createChooser(emailIntent, "Email"));
    }
}

but what i want is that i need to send an email to my account from my phone 但是我想要的是我需要通过手机将电子邮件发送到我的帐户

so if anyone can help me i will appreciate that 所以如果有人可以帮助我,我将不胜感激

Check this code for Sending Emails without User Intervention (no Intents) in Android . 在Android中,请检查以下代码以在没有用户干预的情况下发送电子邮件(无意图) It's a step by step tutorial. 这是一个循序渐进的教程。 Hope this works for ya! 希望这对您有用!

Checkout this link . 签出此链接。 I used it to send email in android from background . 我用它从后台在android中发送电子邮件。 This link is used to send email from gmail account . 该链接用于从gmail帐户发送电子邮件。

https://www.simplifiedcoding.net/android-email-app-using-javamail-api-in-android-studio/ https://www.simplifiedcoding.net/android-email-app-using-javamail-api-in-android-studio/

Then go to your gmail account and follow the steps given below 然后转到您的Gmail帐户并按照以下步骤进行操作

1.Go to the "Less secure apps" section in My Account.Next to "Access for less secure apps," select Turn on. 1.转到“我的帐户”中的“安全应用程序较少”部分。在“访问安全性较低的应用程序”旁边,选择启用。 (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.) (对Google Apps用户的注意:如果您的管理员锁定了安全性较低的应用程序帐户访问权限,则此设置将隐藏。)

2.Go to https://www.google.com/a/YOURDOMAIN/UnlockCaptcha 2.转到https://www.google.com/a/YOURDOMAIN/UnlockCaptcha

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM