当我尝试在Android中使用Mandrill SMTP发送电子邮件时出错

卢西亚诺cba

我在运行我的应用程序API Mandrill响应时使用Android Studio 1.2并出现此错误

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a message value"}

当我检查对象paramsArr时似乎还可以,但是我认为可能是我错过了一些属性,或者我的paramsArr没有正确的结构。

这是paramsArr的结构:

[{"key":"mykey","message":[{"html":"ghgh","text":"test","to":[{"email":"[email protected]","name":"person","type":"to"}],"from_email":"[email protected]","from_name":"person","subject":"erer"}],"async":false}]

摇篮:

compileSdkVersion 21
buildToolsVersion '22.0.1'  
minSdkVersion 16
targetSdkVersion 21

AndroidManifest.xml:

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

发送电子邮件的功能

public void SendEmail(View view) {

                    try {


                        JSONArray paramsArr = new JSONArray();

                        JSONArray paramsArr1 = new JSONArray();
                        JSONArray paramsArr2 = new JSONArray();

                        JSONObject object = new JSONObject();
                        object.put("key", "mykey");


                        JSONObject arrayElementTo = new JSONObject();
                                         arrayElementTo.put("email","[email protected]");
                        arrayElementTo.put("name", "person");
                        arrayElementTo.put("type", "to");

                        paramsArr1.put(arrayElementTo);


                        JSONObject arrayElementMessage = new JSONObject();
                        arrayElementMessage.put("html", "ghgh");
                        arrayElementMessage.put("text", "test");
                        arrayElementMessage.put("to",paramsArr1);
                        arrayElementMessage.put("from_email", "[email protected]");
                        arrayElementMessage.put("from_name", "person");
                        arrayElementMessage.put("subject", "erer");



                        paramsArr2.put(arrayElementMessage);
                        object.put("message",paramsArr2);

                        object.put("async", false);


                        paramsArr.put(object);


                        HttpClient httpclient = new DefaultHttpClient();
                        HttpPost httppost = new HttpPost("https://mandrillapp.com/api/1.0/messages/send.json");

                        StringEntity params = new StringEntity(paramsArr.toString());


                        httppost.setHeader("Content-type", "application/json");
                        httppost.setEntity(params);

                        HttpResponse response = httpclient.execute(httppost);

                        HttpEntity entity = response.getEntity();
                        String responseString = EntityUtils.toString(entity, "UTF-8");


                    }catch (Exception e){

                        Toast toast = Toast.makeText(getApplicationContext(), "error",
                                Toast.LENGTH_SHORT);

                        toast.show();

                    }


    }
卢西亚诺cba

问题出在我的参数json的结构中 [{"key":"mykey","message":[{"html":"ghgh","text":"test","to":[{"email":"[email protected]","name":"person","type":"to"}],"from_email":"[email protected]","from_name":"person","subject":"erer"}],"async":false}]

正确的结构是

{"key":"mykey","message":{"html":"ghgh","text":"test","to":[{"email":"[email protected]","name":"person","type":"to"}],"from_email":"[email protected]","from_name":"person","subject":"erer"},"async":false}

使用此功能,您可以使用此服务从android发送和发送电子邮件,我对此进行了测试,并且效果很好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

尝试在RoR应用程序中发送电子邮件时遇到SMTP错误

通过Office365 smtp使用nodemailer发送电子邮件时出错(MEANjs支架)

使用Gmail SMTP发送电子邮件-Meteorjs

使用SMTP Codeigniter发送电子邮件

使用邮政MVC发送电子邮件时出错?

使用nodemailer发送电子邮件时出错

尝试在Laravel中发送电子邮件时出错

无法使用Outlook SMTP帐户发送电子邮件

使用gmail SMTP从辅助地址发送电子邮件

使用Accounts.sendVerificationEmail()发送电子邮件时出错

使用SMTP在Gmail帐户中发送电子邮件

使用Mandrill(php)发送电子邮件时出错

当我尝试发送电子邮件时,SMTP服务器需要安全的连接

使用SMTP在Gmail上发送电子邮件

使用luasocket smtp和ssl发送电子邮件

使用SMTP发送电子邮件时如何解析换行符

如何使用PHP通过SMTP发送电子邮件

无法使用SMTP发送电子邮件

尝试发送电子邮件时出错

尝试通过 SMTP (Java) 发送电子邮件时出现 java.lang.NoClassDefFoundError

使用 Laravel 使用 Mailgun 发送电子邮件时出错

使用雅虎发送电子邮件时出现 SMTP 异常

通过 sendgrid 使用 ansible 发送电子邮件时出错

使用 nodejs 和 mailgun 发送电子邮件时出错

尝试在 python 3.8.3 中使用 smtplib 发送电子邮件时出错

使用 Nodemailer 发送电子邮件时出错

Python:尝试删除为发送电子邮件附件而生成的文件时出错

NodeJs 无法使用 gmail smtp 发送电子邮件

使用 smtp 发送电子邮件(需要帮助)