如何修复使用 Mandrill API 的崩溃应用?
How to fix a crashing app that uses Mandrill API?
我正在尝试使用我用 Mandrill API 和 this API 构建的 Android 应用程序发送电子邮件。我已经在 Mandrill 中注册了我的应用程序,我从 Mandrill 网站获得了 API 密钥,并将其放入我的应用程序中,但应用程序崩溃了。
我的设备(模拟器)已经连接到互联网。
这是我的 API 关键状态:
这是我的方法和代码
public void sendEmail(){
MandrillMessage allMessage = new MandrillMessage("545b0acfc446e44f6734be###########");
// create your message
EmailMessage message = new EmailMessage();
message.setFromEmail("info@mydocapp.net");
message.setFromName("buddy");
message.setHtml("<p>Your appointment added was successfully</p>");
message.setText("Your appointment date was fixed to 2018");
message.setSubject("Your appointment added was successfully");
// add recipients
Recipient recipient = new Recipient();
List<Recipient> recipients = new ArrayList<Recipient>();
recipient.setEmail("sahanpasindu07@gmail.com");
recipient.setName("Sahan");
recipients.add(recipient);
// add attachment if you want
// Attachment attachment = new Attachment();
// List<Attachment> attachments = new ArrayList<Attachment>();
//
// attachment.setType("image/png");
// attachment.setName("Image name");
// attachment.setContent(" set your base64 encode of your file");
// attachments.add(attachment);
message.setTo(recipients);
// message.setImages(attachments);
allMessage.setMessage(message);
allMessage.send();
}
我的logcat是
> 10-06 17:22:06.231 3871-4223/com.me.doctor.doctor_me E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.me.doctor.doctor_me, PID: 3871
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:451)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我知道有一些方法可以实现我的过程,但我认为 Mandrill 会比 Java Mail API 更容易。但是在 Java 邮件 api 中我发现了一些错误并且还需要对邮件设置进行一些更改,这就是我选择 Mandrill 的原因。我愿意接受更好的方法来做到这一点。
这一行告诉您问题的原因。
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
将 <uses-permission android:name="android.permission.INTERNET" />
行添加到清单的顶部。
我正在尝试使用我用 Mandrill API 和 this API 构建的 Android 应用程序发送电子邮件。我已经在 Mandrill 中注册了我的应用程序,我从 Mandrill 网站获得了 API 密钥,并将其放入我的应用程序中,但应用程序崩溃了。
我的设备(模拟器)已经连接到互联网。
这是我的 API 关键状态:
这是我的方法和代码
public void sendEmail(){
MandrillMessage allMessage = new MandrillMessage("545b0acfc446e44f6734be###########");
// create your message
EmailMessage message = new EmailMessage();
message.setFromEmail("info@mydocapp.net");
message.setFromName("buddy");
message.setHtml("<p>Your appointment added was successfully</p>");
message.setText("Your appointment date was fixed to 2018");
message.setSubject("Your appointment added was successfully");
// add recipients
Recipient recipient = new Recipient();
List<Recipient> recipients = new ArrayList<Recipient>();
recipient.setEmail("sahanpasindu07@gmail.com");
recipient.setName("Sahan");
recipients.add(recipient);
// add attachment if you want
// Attachment attachment = new Attachment();
// List<Attachment> attachments = new ArrayList<Attachment>();
//
// attachment.setType("image/png");
// attachment.setName("Image name");
// attachment.setContent(" set your base64 encode of your file");
// attachments.add(attachment);
message.setTo(recipients);
// message.setImages(attachments);
allMessage.setMessage(message);
allMessage.send();
}
我的logcat是
> 10-06 17:22:06.231 3871-4223/com.me.doctor.doctor_me E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.me.doctor.doctor_me, PID: 3871
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:451)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:96)
at net.soroushjavdan.androidmandrillinterface.MandrillMessage.doInBackground(MandrillMessage.java:88)
at android.os.AsyncTask.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我知道有一些方法可以实现我的过程,但我认为 Mandrill 会比 Java Mail API 更容易。但是在 Java 邮件 api 中我发现了一些错误并且还需要对邮件设置进行一些更改,这就是我选择 Mandrill 的原因。我愿意接受更好的方法来做到这一点。
这一行告诉您问题的原因。
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
将 <uses-permission android:name="android.permission.INTERNET" />
行添加到清单的顶部。