简体   繁体   English

找不到API包“ mail”或调用“ Send()”

[英]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.

相关问题 线程“ main” com.google.apphosting.api.ApiProxy $ CallNotFoundException中的异常:未找到API包“ mail”或调用“ Send()” - Exception in thread “main” com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'mail' or call 'Send()' was not found 没有发现异常,但邮件未在Spring MVC中发送 - No exception found but mail not send in Spring MVC 找不到API包“ memcache”或调用“ Get()” - The API package 'memcache' or call 'Get()' was not found 找不到API包“ memcache”或调用“ FlushAll()” - The API package 'memcache' or call 'FlushAll()' was not found Java Mail API异常 - java mail API exception OAuth 2,无法发送邮件异常 - OAuth 2, cant send the mail exception Spring开机邮件发送异常 - Mail Send Exception in Spring Boot Google App Engine:未找到API包“搜索”或调用“ IndexDocument()” - Google App Engine: The API package 'search' or call 'IndexDocument()' was not found 使用twilio发送短信:未找到API包'urlfetch'或调用'Fetch()' - Sending sms with twilio: The API package 'urlfetch' or call 'Fetch()' was not found 未找到API包'remote_socket'或调用'Resolve()' - GAE Java - The API package 'remote_socket' or call 'Resolve()' was not found - GAE Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM