[英]send mail from android without using smtp and user interaction
I want to send email from my android application without any user interaction . 我想从我的android应用程序发送电子邮件,而无需任何用户交互 。 How can i implement services like Mailgun API in android?
如何在Android中实现Mailgun API等服务?
I found a piece of code in mailgun that works in java . 我在mailgun中发现了一段可在java中工作的代码。 For this implementation i got some libraries that doesnot works with android.
对于此实现,我得到了一些不适用于android的库 。 Anybody have tried to use mailgun in android?
有人试图在Android中使用Mailgun吗?
I think what you are asking is outbound sender email which is similar to Mailgun. 我认为您要问的是与Mailgun类似的出站发件人电子邮件。 One such service is Amazon SES which is already incorporated into AWS Mobile SDK .
一种这样的服务是Amazon SES,该服务已经集成到AWS Mobile SDK中 。 It even has a nice tutorial to implement it in Android.
它甚至还有一个很好的教程 ,可以在Android中实现它。 Both SES and Mailgun require a verified sender so technically you will be sending emails from your own domain and have nothing to do with user's email.
SES和Mailgun都需要经过验证的发件人,因此从技术上讲,您将从自己的域发送电子邮件,而与用户的电子邮件无关。
Send Mail basic implementation, via MailGun API and Retrofit for Android: 通过MailGun API和Retrofit for Android发送邮件的基本实现:
public class MailGun {
private static final String TAG = MailGun.class.getSimpleName();
private static final boolean DEBUG = Config.DEBUG;
private static final String ENDPOINT = "https://api.mailgun.net/v3/yourdomain.com/";
public static final String ACCEPT_JSON_HEADER = "Accept: application/json";
public static final String BASIC = "Basic";
private SendMailApi sendMailApi;
public interface SendMailApi {
@Headers({ACCEPT_JSON_HEADER})
@FormUrlEncoded
@POST("/messages")
void authUser(
@Header("Authorization") String authorizationHeader,
@Field("from") String from,
@Field("to") String to,
@Field("subject") String subject,
@Field("text") String text,
Callback<MailGunResponse> cb
);
}
public void sendMail(String to, String subject, String msg, Callback<MailGunResponse> cb){
String from = "User Name Maybe <mailgun@yourdomain.com>";
String clientIdAndSecret = "api" + ":" + "key-AdFEFtggxxxYourApiKey";
String authorizationHeader = BASIC + " " + Base64.encodeToString(clientIdAndSecret.getBytes(), Base64.NO_WRAP);
sendMailApi.authUser(authorizationHeader,from, to, subject, msg, cb);
}
public MailGun() {
RestAdapter restAdapter = getAuthAdapter();
sendMailApi = restAdapter.create(SendMailApi.class);
}
private RestAdapter getAuthAdapter(){
RestAdapter.LogLevel logLevel = RestAdapter.LogLevel.NONE;
if(DEBUG)logLevel = RestAdapter.LogLevel.FULL;
return new RestAdapter.Builder()
.setEndpoint(ENDPOINT)
.setConverter(new GsonConverter(new Gson()))
.setLogLevel(logLevel)
.build();
}
}
Complete Github gist: https://gist.github.com/hpsaturn/5fd39a4e7d6ffb156197 完整的Github要点: https : //gist.github.com/hpsaturn/5fd39a4e7d6ffb156197
I would suggest to use javamail. 我建议使用javamail。 It works fine for me and works on android.
它对我来说很好用,并且可以在android上使用。 Here is the link to the google code project .
这是Google代码项目的链接 。 Although you don't have as much possibilities as in mailgun, for just sending a mail javamail is enough.
尽管您没有mailgun中的可能性很多,但是仅发送邮件javamail就足够了。
let key = "dfasewr4353terf34t43fefdf34r"
let EmailBody = "<html><body><table border='1'><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr>td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table></body></html>"
let parameters = [
"from":from@fromme.com,
"to": to@tome.com,
"subject": "my Email Subject",
"html": EmailBody,
"text" = "some text instead of html.Only one is aloowed either text or HTML"
]
Alamofirerequest(.POST, "https://api.mailgun.net/v3/<MAILGUN-DOMAIN>/messages", parameters:parameters)
.authenticate(user: "api", password: key)
.response { (request, response, data, error) in
println(request)
println(response)
println(error)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.