我已经知道如何通过Google Engine接收电子邮件。现在我正在尝试发送收到电子邮件的确认,但我一直收到此错误:
com.jkimgroup.emailtospreadsheet.MailHandlerServlet doPost:
MessagingException: javax.mail.SendFailedException:
Send failure (javax.mail.MessagingException:
Could not connect to SMTP host: localhost, port: 25 (java.net.SocketException: Permission denied:
Attempt to access a blocked recipient without permission.))
我将“发件人”地址设置为我的管理员电子邮件。这是一条错误消息,也许我没有在/ WEB-INF / lib文件夹中包含正确的jar文件?
我使用谷歌的标准示例:https://developers.google.com/appengine/docs/java/mail/usingjavamail
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("admin@example.com", "Example.com Admin"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("user@example.com", "Mr. User"));
msg.setSubject("Your Example.com account has been activated");
msg.setText(msgBody);
Transport.send(msg);
} catch (AddressException e) {
// ...
} catch (MessagingException e) {
// ...
}
更新 我开始认为,即使官方文档指向使用JavaMail 1.4.7,我也可能会使用appengine librares进行邮件处理?
如果是这种情况,这里是我在代码中导入的库。
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.TimeZone;
import java.util.logging.Logger;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//Am I supossed to import this one instead of the javax.mail.* jars?
//import com.google.appengine.api.mail.MailService.Message;
import com.google.appengine.api.users.User;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
更新2现在固定 我在Oracle的JavaMail JAR中添加了我的应用程序,这确实导致了以下问题:
您需要的所有JavaMail类都包含在App Engine中 SDK。不要将Oracle®的JavaMail JAR添加到您的应用程序中;如果你这样做的话 应用程序将抛出异常。
https://developers.google.com/appengine/docs/java/mail/?csw=1
答案 0 :(得分:0)
这不是一个明确的答案......
异常消息说明了这一点:
Could not connect to SMTP host: localhost, port: 25
(java.net.SocketException: Permission denied:
Attempt to access a blocked recipient without permission.))
因此传输尝试使用与GAE在同一台计算机上运行的SMTP服务。但错误消息似乎表明它成功连接,并且SMTP服务拒绝接受电子邮件以传递给任何收件人。
所以我建议您执行以下操作: