使用javamail发送邮件不起作用 [英] Sending mail using javamail not working

查看:123
本文介绍了使用javamail发送邮件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的Gmail地址发送和发送电子邮件. 我将debug设置为true,这就是我得到的.

I'm trying to send and email using my gmail address. I set debug to true and this is what I get.

DEBUG: JavaMail version 1.4.1
DEBUG: not loading file: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javamail.providers
DEBUG: java.io.FileNotFoundException: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javamail.providers (No such file or directory)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javamail.address.map
DEBUG: java.io.FileNotFoundException: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javamail.address.map (No such file or directory)

DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true

然后我什么也不做,没有错误/警告/....

And then I does just nothing, no error/warning/....

我正在使用这些设置:

mail.smtp.auth=true
mail.debug=true
mail.smtp.host=smtp.gmail.com
mail.smtp.user=MyOwnUserName@gmail.com
mail.smtp.password=MyOwnPassword
mail.transport.protocol=smtp
mail.smtp.port=465
mail.disable=false
mail.verbose=true
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

我尝试了这些示例:

  1. http://adfblogs.blogspot .be/2012/01/sending-e-mail-from-adf-application.html
  2. 使用Java发送电子邮件
  1. http://adfblogs.blogspot.be/2012/01/sending-e-mail-from-adf-application.html
  2. Send email using java

所有相同的问题.而且我100%确定我的密码和emailadress是正确的.

All the same problem. And I'm 100% sure my password and emailadress is correct.

我的代码(与第一个链接相同) nitialContext ic = new InitialContext(); 会话会话=(会话)ic.lookup("mail/SugarCRMMailSession");

My code (the same as in the first link) nitialContext ic = new InitialContext(); Session session = (Session) ic.lookup("mail/SugarCRMMailSession");

        Properties props = session.getProperties();

        String  to = emailID;

        String mailhost = props.getProperty("mail.smtp.host");
        String user = props.getProperty("mail.smtp.user");
        String password = props.getProperty("mail.smtp.password");
        String protocol = props.getProperty("mail.transport.protocol");

        String authorization = props.getProperty("mail.smtp.auth");
        String mailDisabled = props.getProperty("mail.disable");
        String verboseProp = props.getProperty("mail.verbose");
        String debugProp = props.getProperty("mail.debug");

        boolean sentDisabled = false;
        if(mailDisabled.equals("true"))
            sentDisabled = true;

        if(!sentDisabled){

            boolean auth = false;
            if(authorization.equals("true"))
                auth = true;

            boolean verbose = false;
            if(verboseProp.equals("true"))
                verbose = true;

            String mailer = "smtpsend";

            if(debugProp.equals("true"))
                session.setDebug(true);
            else
                session.setDebug(false);

            Message msg = new MimeMessage(session);
            msg.setFrom();      
            msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
            msg.setSubject(subject);
            msg.setContent(text, "text/html;charset=UTF-8");      
            msg.setHeader("X-Mailer", mailer);
            msg.setSentDate(new Date());

            SMTPTransport t = (SMTPTransport)session.getTransport(protocol);

            try {
                t.connect(mailhost, user, password);
                t.sendMessage(msg, msg.getAllRecipients());
            } finally {
                    t.close();
            }

             System.out.println("\nMail was sent successfully.");
        }else{
             System.out.println("Mail Sending is disabled.");
        }

推荐答案

在这里,这是解决您问题的完美解决方案

Here this is perfect solution for your problem download Mail api jar form here

Api的Gmail邮件提供商

只需转到Windows->首选项-> Java->已安装的JRES->

and just go to Windows --> Preferencs --> Java --> Installed JRES -->

以及您正在使用的JRE,只需选择它并进行编辑,然后将该外部jar添加到该JRE中,然后单击okey,然后Compiler将能够加载该jar文件.因此错误将得到解决.

and what ever JRE You are using just select it and EDIT and then add that external jar into that JRE and Click okey then Compiler will able to load that jar file. hence the error will get resolved.

尝试一下.

这篇关于使用javamail发送邮件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆