用Appengine发邮件

用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("[email protected]"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(sendto, ""));
            msg.setSubject(subject);
            msg.setText(content);
            Transport.send(msg);
        } catch (AddressException e) {
        	
        } catch (MessagingException e) {
        	
        }
	}
}


你可能感兴趣的:(java,Google,配置管理,Gmail,GAE)