简体   繁体   English

如何从应用程序发送电子邮件

[英]How to Send Email from App

I need to send emails from an app. 我需要通过应用发送电子邮件。 Until now I've used the JavaMail Api which works well but has some problems: 到目前为止,我使用的JavaMail Api效果很好,但存在一些问题:

  • I need to hardcode the password to the gmail account from which the mails should be sent, which obviously isn't great 我需要将密码硬编码到应该从中发送邮件的gmail帐户,这显然不是很好
  • Google recently detected some "suspicious sign ins" (I don't know if this was actually some people who tried to access the account or just the normal sign ins from the app), but google forced me to change the password, which obviously made the app useless because it couldn't send emails anymore. Google最近检测到一些“可疑登录”(我不知道这实际上是不是有人试图访问该帐户,或者只是从应用程序正常登录),但是Google强迫我更改了密码,这显然使该应用程序无用,因为它无法再发送电子邮件了。

I don't want to always release an update just because I had to change the password. 我不想仅因为必须更改密码而总是发布更新。

So if you have any ideas on how to either: 因此,如果您对如何操作有任何想法:

  • make the hardcoded password pretty secure and preventing google from forcing me to change the password 使硬编码密码非常安全,并防止Google强迫我更改密码

  • or sending the emails some other way that doesn't need a hardcoded password (like through a http request but that doesn't really work because the server thinks I'm spamming around and blocks the webspace...) 或通过其他方式发送电子邮件,而无需使用硬编码的密码(例如通过http请求,但实际上无法正常工作,因为服务器认为我正在垃圾邮件并阻止了网站空间...)

Please help! 请帮忙!

If you want the app to generate emails and send them to the user the best way is to send the email from a backend system. 如果您希望应用程序生成电子邮件并将其发送给用户,则最好的方法是从后端系统发送电子邮件。 Publish a REST API that your mobile application can interact with and have that backend deal with sending the email. 发布您的移动应用程序可以与之交互的REST API,并让后端处理发送电子邮件。 It will be more secure and you'll have proper decoupling. 它将更加安全,并且您将具有适当的去耦。 It's the only good way to deal with it. 这是处理它的唯一好方法。

Encoded passwords in an app can always be decrypted, as the encryption key will also be stored somewhere in the app. 应用程序中的编码密码始终可以解密,因为加密密钥也将存储在应用程序中的某个位置。 Plus as you already stated, the hassle of having that code sitting in your app, and the difficulty of updating that code can be a nightmare (not all users update their apps frequently). 另外,正如您已经说过的那样,将代码放在应用程序中的麻烦以及更新代码的困难可能是一场噩梦(并非所有用户都经常更新其应用程序)。

If you want the app to send emails on behalf of the user (making it as if the user is sending them), then use an Intent as CommonsWare stated in the comments. 如果您希望该应用程序代表用户发送电子邮件(使其像用户正在发送电子邮件一样),请使用Intent作为CommonsWare,如注释中所述。 It makes it visible to the user that an email is sent. 用户可以看到发送了电子邮件。

Not sure how often it has to send emails, but you could encrypt the password with a 4-digit pin, then upon startup ask for the pin, decrypt the password and keep it in memory. 不确定发送电子邮件的频率,但是您可以使用4位数的密码对密码进行加密,然后在启动时要求输入密码,解密密码并将其保存在内存中。 You'll need to re-decrypt it if you get swapped out, but it will keep the user's password more secure. 如果您换了出去,则需要重新解密,但这将使用户密码更加安全。

I concur with ddewaele: a proper API is necessary. 我同意ddewaele的观点:适当的API是必需的。 Note that there are online services that offer easy APIs for you. 请注意,有些在线服务可以为您提供简单的API。 For some examples, see Backend server provider for mobile apps . 有关某些示例,请参阅移动应用程序的后端服务器提供程序 Some are free for a small number of users. 有些对少数用户免费。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM