1

你们让我有自我意识。我会努力让这个变得更好。

好的,据我所知,这个程序(不要杀了我..我下载了它)仅适用于 Windows 7 和 Ubuntu。当您在 Windows 8 上打开它时,它会显示“Java 异常错误”。

我认为这与catch(messagingException ex)文件末尾有关。我承认,我对 java 知之甚少,但你必须从某个地方开始......不是吗?我知道java适用于所有平台!

我还用多个文件和多个 Gmail 帐户尝试过这个程序……我什至用我的 Comcast 电子邮件地址尝试过。
我将“JavaMailAPI”(http://www.oracle.com/technetwork/java/javamail/index.html)用于实际的邮件部分。

当我在 Windows 8 的终端上打开它时,它给了我这个:

Exception in thread "Main" java.lang.noclassdeffounderror: java/mail/mailexception
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.langf.Class.privateGetDdecLaredMethods(Unkown source)
at java.lang.Class.getMethod(unknown source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown source)
caused by: java.lang.classnotfoundexception: java.mail.messagingException
at java.net.URLCLassLoader$1.run(unknown source)
at java.net.URLClassLoader$1.run(Unknown source)
at java.security.AccessController.doPrivaleged(native Method)
at java.net.URLClassLoader.findClass(Unknown source)
at java.lang.ClassLoader.findClass(Unkown source)
at jaa.lang.CLassLoader.loadClass(Unknown source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown source)
at java.lang.ClassLoader.loadClass(Unknown source)
... 6 more

这是代码:

package testing;

import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Testing{
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("Email","Password");
                }
            });

        try {
                        BodyPart messageBodyPart = new MimeBodyPart();
                        Multipart multipart = new MimeMultipart();
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("Email Address"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("Email Address to send "));
            message.setSubject("Subject");
            message.setText("Message");
                         String filename = "attachment location";
         DataSource source = new FileDataSource(filename);
         message.setDataHandler(new DataHandler(source));
         message.setFileName(filename);
         multipart.addBodyPart(messageBodyPart);
            Transport.send(message);
            System.out.println("Done");
                } catch (MessagingException ex) {
                Logger.getLogger(Testing.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}

如果您需要有关该程序的任何其他信息,请询问!

4

1 回答 1

0

您必须下载 Java 邮件

如果此应用程序需要 JavaMail,您应该构建一个安装程序以将所需的 JAR 打包并安装为 JavaMail。

于 2013-02-17T15:49:06.920 回答