[英]The API package 'mail' or call 'Send()' was not found Exception
I write the following code for send mail.(java maven web application). 我为发送邮件编写了以下代码。(java maven Web应用程序)。
public class MailAction extends ActionSupport { 公共类MailAction扩展了ActionSupport {
private String mailId;
public String getMailId() {
return mailId;
}
public void setMailId(String mailId) {
this.mailId = mailId;
}
final String username = "my email";
final String password = "my password";
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse servletResponse;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("my email"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(request.getParameter("mailId")));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
System.out.println(request.getParameter("mailId"));
System.out.println(message);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
return SUCCESS;
}
When i run the program The API package 'mail' or call 'Send()' was not found Exception appear. 当我运行程序时,未找到API包“ mail”或调用“ Send()”,但出现异常。 Please help me to solve this problem.
请帮我解决这个问题。
The issue is with "Transport" see attached code 问题在于“运输”,请参见随附的代码
Transport transport = session.getTransport("smtp");
transport.connect("smtp.gmail.com", 465, "username", "password");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.