Im tring để gửi một email đơn giản với mã này bằng cách sử dụng công cụ ứng dụng của google. Nhưng không có gì xảy ra, có điều gì tôi phải cấu hình để sử dụng api thư không? Điều này chạy trên máy chủ cục bộ. Tôi đang sử dụng gmail làm máy chủ thư.Gửi email bằng công cụ ứng dụng google
String host = "smtp.google.com";
String to = "[email protected]";
String from = "[email protected]";
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);
Vì vậy, không có cách nào để gửi email từ dự án GAE? Hoặc không sử dụng cách này? – Nick
Bạn có thể, chỉ từ các địa chỉ cụ thể và máy chủ phát triển cục bộ chỉ ghi nhật ký email vào bảng điều khiển – jimr