2013-11-03 120 views
0

我打算使用Google App Engine部署Web应用程序。如果其他用户在用户的页面上执行某些操作,应用程序会通过电子邮件向用户发送警报。在这种情况下,有什么方法可以通过电子邮件向用户发送通知?发送电子邮件提醒来自Google App Engine

+1

这将有助于 - https://developers.google.com/appengine/docs/python/mail/ –

+0

@AshishNitinPatil是Python的... – Lipis

+0

我很抱歉。在这里你可以去 - https://developers.google.com/appengine/docs/java/mail/ –

回答

1

是的,你可以使用JavaMail to Send Mail。下面是从文档取一个例子:

import java.util.Properties; 

import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.AddressException; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

// ... 
     Properties props = new Properties(); 
     Session session = Session.getDefaultInstance(props, null); 

     String msgBody = "..."; 

     try { 
      Message msg = new MimeMessage(session); 
      msg.setFrom(new InternetAddress("[email protected]", "Example.com Admin")); 
      msg.addRecipient(Message.RecipientType.TO, 
          new InternetAddress("[email protected]", "Mr. User")); 
      msg.setSubject("Your Example.com account has been activated"); 
      msg.setText(msgBody); 
      Transport.send(msg); 

     } catch (AddressException e) { 
      // ... 
     } catch (MessagingException e) { 
      // ... 
     } 

这也是很重要的发件人地址必须是以下类型之一:

  • 注册管理员为应用
  • 地址使用Google帐户登录的当前请求的用户地址。您可以使用用户API确定当前用户的电子邮件地址。用户的帐户必须是 - Gmail帐户,或者位于Google Apps管理的域中。
  • 该应用的任何有效的电子邮件接收地址(例如[email protected])。
相关问题