Arm*_*iye 5 java email google-app-engine
我想使用谷歌应用引擎发送一个包含此代码的简单电子邮件.但没有任何反应,为了使用邮件api,我必须配置一些东西吗?这在localhost上运行.我使用gmail作为邮件主机.
String host = "smtp.google.com";
String to = "example@yahoo.fr";
String from = "example@gmail.com";
String subject = "this is a test";
String messageText = "test";
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
// Set debug on the Session
// Passing false will not echo debug info, and passing True will.
mailSession.setDebug(sessionDebug);
// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6178 次 |
| 最近记录: |