【问题标题】:send mail using Amazon web SES from android application从 Android 应用程序使用 Amazon Web SES 发送邮件
【发布时间】:2017-03-25 09:11:36
【问题描述】:

我正在开发一个应用程序,我想在没有用户干预的情况下从应用程序发送邮件(不使用意图)。获取用户凭据并不好(不使用 java 邮件 API)。但是如何绑定正文从 android 应用程序到 Web API 的邮件。这是我的代码。

 public void onClick(View v) {
 if (v == btnSend) {
 String url = "http://app.xyz.com/api/SendMail/SendMail?Emailid=xyz@gmail.com" + "&Subject=" + "&Body=";
       if (url != null) {
            email = editTextEmail.getText().toString();
            subject = editTextSubject.getText().toString();
            message = editTextMessage.getText().toString();
            final Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[]{"xyz@gmail.com"});
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
            this.startActivity(Intent.createChooser(emailIntent, "Sending email..."));

           }
           }catch (Throwable t) {
            Toast.makeText(this,
           "Request failed try again: " + t.toString(),
            Toast.LENGTH_LONG).show();
       }
    }

【问题讨论】:

  • 您可以使用 SMTP 发送
  • 在发布这个问题时,我在堆栈溢出中进行了搜索。但我没有得到正确的方法。首先了解我的帖子。使用 Java Mail API 时,它会要求用户输入名称和密码。而且出于安全考虑,我不想在我的应用中使用密码。
  • 忘记用户名和密码是用于 SMTP 的,所以你可以静态添加它
  • 请解释一下如何实现

标签: android api email web amazon-ses


【解决方案1】:

我终于找到了解决方案。为了使用 Amazon SES 发送邮件。

我们应该拥有 Amazon 凭证。使用该凭证并使用 Web API 在 .net 中编写控制器,并在我们的 android 应用程序中调用 URL。

下面是我的安卓代码。

public void onCreate(Bundle savedInstanceState)
   {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feed_back);
    scanBtn = (Button) findViewById(R.id.button1);
    myAwesomeTextview = (TextView) findViewById(R.id.myAwesomeTextview);
    scanBtn.setOnClickListener(new View.OnClickListener()
    {
    public void onClick(View view)
    {
    mEdit = (EditText) findViewById(R.id.editText1);
    mText = (TextView) findViewById(R.id.textView2);
    Subject = mEdit.getText().toString();
    mEdit1 = (EditText) findViewById(R.id.editText2);
    mText1 = (TextView) findViewById(R.id.textView3);
    Body = mEdit1.getText().toString();
    Log.d("###$Request URL", Subject + "");
    Log.d("###$Request URL", Body + "");
    SharedPreferences sharedpreferences = getSharedPreferences(main.MyPREFERENCES, Context.MODE_PRIVATE);
    String  e = sharedpreferences.getString(main.email,"");
    String url ="http://app.xyz.com/Api/SendMail/SendMail?Emailid="+ e + "&Subject="+ Subject+"&Body=" +Body;
    AQuery mAQuery = new AQuery(FeedBack.this);
    mAQuery.ajax(url, String.class, new AjaxCallback<String>()
    {
    @Override
    public void callback(String url, String data, AjaxStatus status)
    {
    super.callback(url, data, status);
    if (BuildConfig.DEBUG)
    {
        Log.d("###$Request URL", url + "");
        Log.d("###$Response ", data + "");
        Log.d("###$Status Message : ", status.getMessage() + "");
        Log.d("###$Status Code : ", status.getCode() + "");

    }
    if(status.getCode()!=-101)
    {
       String StringData = "" + data;
       try 
       {
         JSONObject json = new JSONObject(StringData);
         String sd,hd;
         sd = json.getString("Subject");
         hd=  json.getString("Body");

       } 
       catch (Exception a) 
       {
          Toast toast = Toast.makeText(FeedBack.this,"Mail Sending", Toast.LENGTH_LONG);
          toast.setGravity(Gravity.CENTER, 0, 0);
          toast.show();
       }
       }
       else
       {
         Toast toast = Toast.makeText(FeedBack.this,"Please Check Your Internet Connection", Toast.LENGTH_LONG);
         toast.setGravity(Gravity.CENTER, 0, 0);
         toast.show();

       }
        }
        });
        }
     });
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多