Java Mail方法尚未实现mimemessage

时间:2013-02-25 09:40:18

标签: java javamail

将错误视为“尚未实施的方法mimemessage”

尝试发送电子邮件时

   protected static void addAtachments(String[] attachments, Multipart multipart) throws MessagingException, MessagingException {

    for (int i = 0; i <= attachments.length - 1; i++) {
    String filename = attachments[i];
    MimeBodyPart attachmentBodyPart = new MimeBodyPart();

    DataSource source = new FileDataSource(filename);
    attachmentBodyPart.setDataHandler(new DataHandler(source));

    attachmentBodyPart.setFileName(filename);
    multipart.addBodyPart(attachmentBodyPart);
}}



  protected static void sendMessage(List<String> recipients, String subject,
                              String messageContent, String from, String[] attachments)
    throws MessagingException, MessagingException {
boolean debug = false;

Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(props,
        new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("xxxxx", "xxxxxx");
            }
        });

session.setDebug(debug);

Message message = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
message.setFrom(addressFrom);

for (String recipient : recipients) {
    message.addRecipient(Message.RecipientType.TO,
            new InternetAddress(recipient));
}

message.setSubject(subject);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(messageContent, "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
addAtachments(attachments, multipart);

message.setContent(multipart);
Transport.send(message);}

异常

Exception in thread "main" java.lang.UnsupportedOperationException: Method not yet implemented
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:89)
at uk.co.newsint.bp.reg.report.Main.sendMessage(Main.java:84)
at uk.co.newsint.bp.reg.report.Main.main(Main.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

3 个答案:

答案 0 :(得分:1)

请确保java邮件依赖项如下 1,

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.7</version>`
</dependency>

因为还有另一个jar包括javax.mail.* 包裹在下面 2,

<dependency>
    <groupId>geronimo-spec</groupId>
    <artifactId>geronimo-spec-j2ee</artifactId>
    <version>1.4-rc4</version>`
</dependency>

解决方案是用第一个依赖替换第二个依赖

答案 1 :(得分:0)

你已经制作了一些common JavaMail mistakes。 JavaMail FAQ还有其他可能对您有所帮助的示例。

目前尚不清楚这与你获得的例外情况有什么关系。您使用的是什么版本的JavaMail?

如果你在IntelliJ之外运行它,应用程序也会失败吗?

答案 2 :(得分:0)

使用message.addRecipients()来实现。没有&#34; s&#34;最后,JAVAMAIL API REFERENCE IMPLEMENTATION没有实现。查看从

下载的资源

https://java.net/projects/javamail/downloads/directory/source