在我的应用中尝试使用发送网格发送电子邮件。
在我的AsyncTask的doInBackground方法中,我有以下代码
SendGrid sendgrid = new SendGrid("XXXXXX", "YYYYYY");
publishProgress("Preparing mail message....");
SendGrid.Email email = new SendGrid.Email();
email.setFrom(args[0].toString());
email.addTo(args[2].toString());
email.setSubject(args[3].toString());
email.setText(args[4].toString());
// androidEmail.createEmailMessage();
publishProgress("Sending email....");
try {
sendgrid.send(email);
} catch (SendGridException e) {
System.out.println(e);
Log.i("SendGrid Exception", "Mail Not Sent.");
}
publishProgress("Email Sent.");
当我辜负他时,我得到以下错误:
Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory. <init>(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.sendgrid.SendGrid.<init>(SendGrid.java:59)
我从他们的github页面下载send-grod.jar。我用示例java程序测试了它,我可以成功发送邮件。但它在Android中不起作用。
我缺少什么。?