Tag: javax.mail

Tomcat中JNDI的Java Mail API配置文档

我花了几天的时间来弄清楚如何通过JNDI在Tomcat中配置javax.mail.Session并进行身份validation ,现在我得到了它,但只是在深入研究代码之后。 在这段时间里,我看到了有史以来最糟糕的代码:javax.mail.Service #connect(String,String,String,String)Version 1.4.1 if (user == null) { user = url.getUsername(); if (password == null) // get password too if we need it password = url.getPassword(); } else { if (password == null && user.equals(url.getUsername())) // only get the password if it matches the username password = url.getPassword(); } 密码何时分配? 为什么两次检查null? – 然后意识到其他不属于if […]

如何解决地址无效的exception

我们尝试使用javax.mail发送邮件。 发送邮件时,我们遇到以下exception: **sendMail – Message Sending Failed: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 550 #5.1.0 Address rejected.2013-02-28 13:17:08,236** 可能是什么问题?

如何更正无效协议:null使用javax.mail发送邮件

我正试图以这种方式发送邮件: Properties props = new Properties(); props.setProperty(“mail.transport.protocol”, “smtp”); props.setProperty(“mail.host”, “out.alice.it”); props.setProperty(“mail.user”, “mymail@domain.it”); props.setProperty(“mail.password”, “*****”); Session mailSession = Session.getDefaultInstance(props, null); Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(“Host”, “Name”)); 在行Transport transport…我检索此错误: javax.mail.NoSuchProviderException: Invalid protocol: null at javax.mail.Session.getProvider(Session.java:440) at javax.mail.Session.getTransport(Session.java:659) at javax.mail.Session.getTransport(Session.java:640) at javax.mail.Session.getTransport(Session.java:626) at Mail.sendMail(Mail.java:151) 我怎么解决? 有人能帮我吗? 谢谢!! 🙂 编辑: 如果我创建一个main并启动该方法来发送邮件,它的效果很好! 我将邮件发送到邮件文件夹后,我的问题就出现了: Properties […]

Exchange服务器不接受javax.mail API提供的用户名/密码

我有一个可爱的小Java客户端发送签名的电子邮件。 我们有一台Exchange服务器,需要用户名/密码validation才能发送邮件。 当我连接到Exchange服务器时,我收到此错误: avax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connect(Service.java:322) at javax.mail.Service.connect(Service.java:172) 当我连接到其他服务器(Unix服务器)时,我没有问题。 以下是完整的调试跟踪。 我无法弄明白。 DEBUG: JavaMail version 1.4.2 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.SM} DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], } DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] […]

javax.mail.AuthenticationFailedException Java Mail

我制作了一个小程序,将消息发送到我的电子邮件帐户。 我的大多数代码似乎都运行正常。 但是,当我的代码在我的程序中命中transport.send时,我遇到了AuthenticationFailedException。 我不确定为什么,因为我认为我已经正确设置了所有内容。 这是我的代码。 JavaEmail.java public static void main (String[] args) throws Exception{ //intialize logger protected static Logger logger = LogManager.getLogger(JavaEmail.class.getName()); //smtp related parameters private static String smtpUseremail; private static String smtpReceiverEmailAddress; private static String smtpUserpassword; private static String smtpPortnumber; private static String smtpHost; private static String emailSubject; //stack error message variable private static […]

发送邮件:java.net.SocketException:网络无法访问:连接

尝试通过javax.mail发送邮件: Properties props = new Properties(); props.put(“mail.smtp.host”, “xxxxx”); props.put(“mail.smtp.port”, “25”); props.put(“mail.smtp.auth”, “false”); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(“xx”, “xx”); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(“xxxxx”)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(“xxxxx”)); message.setSubject(“Subject”); message.setText(“Body”); Transport.send(message); System.out.println(“Done”); } catch (MessagingException e) { throw new RuntimeException(e); } 它抛出exception Exception […]

javax.mail.AuthenticationFailedException:连接失败,没有指定密码?

此程序尝试发送电子邮件但会引发运行时exception: javax.mail.AuthenticationFailedException: failed to connect, no password specified? 当我提供正确的用户名和密码进行身份validation时,为什么会出现此exception? 发件人和收件人都有g-mail帐号。 发件人和收件人都有g-mail帐号。 发件人已禁用两步validation流程。 这是代码: import javax.mail.*; import javax.mail.internet.*; import java.util.*; class tester { public static void main(String args[]) { Properties props = new Properties(); props.put(“mail.smtp.host” , “smtp.gmail.com”); props.put(“mail.stmp.user” , “username”); //To use TLS props.put(“mail.smtp.auth”, “true”); props.put(“mail.smtp.starttls.enable”, “true”); props.put(“mail.smtp.password”, “password”); //To use SSL props.put(“mail.smtp.socketFactory.port”, “465”); props.put(“mail.smtp.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”); […]

无需身份validation即可在javax.mail中发送邮件

我使用javax.mail在Java中发送邮件。 既然我的项目概念的一部分发生了变化,我必须发送邮件而不进行身份validation。 我将不得不改变我的createSession()方法: private void createSession() { properties.put(“mail.smtp.auth”, “true”); properties.put(“mail.smtp.starttls.enable”, “true”); properties.put(“mail.smtp.host”, server); properties.put(“mail.smtp.port”, port); session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); } 很明显我应该将mail.smtp.auth更改为false ,但我还应该改变什么呢?

如何使用javax.mail读取邮件正文中的文本

我正在使用javax.mail开发客户端邮件来读取邮箱内的邮件: Properties properties = System.getProperties(); properties.setProperty(“mail.store.protocol”, “imap”); try { Session session = Session.getDefaultInstance(properties, null); Store store = session.getStore(“pop3”);//create store instance store.connect(“pop3.domain.it”, “mail.it”, “*****”); Folder inbox = store.getFolder(“inbox”); FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); inbox.open(Folder.READ_ONLY);//set access type of Inbox Message messages[] = inbox.search(ft); String mail,sub,bodyText=””; Object body; for(Message message:messages) { mail = message.getFrom()[0].toString(); sub = […]