我想使用sendgrid从我在android studio中开发的Google终结点项目发送电子邮件。问题是我找不到如何导入sendgrid库的任何示例,我尝试了此方法和其他一些变体:
compile 'com.sendgrid:1.0.6'
最新版本1.0.6在哪里?我可以找到
cfl的答案实际上不适用于最新版本的Android Studio。使用Send-Grid java依赖项会与Android Studio固有的各种依赖项发生冲突。值得庆幸的是,我找到了Dany Santiago制作的分叉版本。在他的示例中,他使用用户名和密码来实例化SendGrid对象,但是如果您具有API密钥,则可以使用该密钥来避免将帐户信息保存在设备上。将此添加到Android Studio项目的build.gradle(应用程序)中的依赖项中:
compile 'com.github.danysantiago:sendgrid-android:1'
不要在Android Studio中使用sendgrid-java,它将无法正常工作。有关更多信息,请参见以下链接https://github.com/danysantiago/sendgrid-android
另外,您无需使用链接中使用的示例。如果您具有sendgrid的API密钥,则此示例代码将可以正常工作:
//Might need other imports
import com.sendgrid.SendGrid;
import com.sendgrid.SendGridException;
import android.util.Log;
//Your method you are sending the email from
public void sendEmail() {
//Alternate way of instantiating
//SendGrid sendGrid = new SendGrid(SENDGRID_USERNAME,SENDGRID_PASSWORD);
//Instantiate the object using your API key String
SendGrid sendgrid = new SendGrid('YOUR_SENDGRID_API_KEY');
SendGrid.Email email = new SendGrid.Email();
email.addTo("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Hello World");
email.setText("My first email with SendGrid Java!");
try {
SendGrid.Response response = sendgrid.send(email);
}
catch (SendGridException e) {
Log.e("sendError", "Error sending email");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句