`
joeblow
  • 浏览: 176098 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

用Appengine发邮件

    博客分类:
  • JEE
阅读更多
用GAE发邮件不用配置SMTP(默认即是SMTP),并且考虑到安全原因,发件人只能是GAE账户管理员或google登陆用户(参考GAE DOC

import java.io.UnsupportedEncodingException;
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;

public class Mailer {

	public void send(String sendto,String subject,String content) throws UnsupportedEncodingException{
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("user@gmail.com"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(sendto, ""));
            msg.setSubject(subject);
            msg.setText(content);
            Transport.send(msg);
        } catch (AddressException e) {
        	
        } catch (MessagingException e) {
        	
        }
	}
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics