Tag: javamail

MimeMessage.saveChanges真的很慢

由于包含m.saveChanges() ,以下测试大约需要5秒钟才能执行。 import org.junit.Before; import org.junit.Test; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.MimeMessage; import java.io.IOException; import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @Test public void test1() throws MessagingException, IOException { Session s = Session.getDefaultInstance(new Properties()); MimeMessage m = new MimeMessage(s); m.setContent(“Hello”, “text/html; charset=utf-8”); m.saveChanges(); assertEquals(m.getContent(), “Hello”); assertEquals(m.getContentType(), “text/html; charset=utf-8”); } 我也用mockito嘲笑了Session,但它没有帮助: Session […]

如何解决javax.mail.AuthenticationFailedException问题?

我正在使用JavaMail执行sendMail Servlet 。 我的输出上有javax.mail.AuthenticationFailedException 。 有人可以帮帮我吗? 谢谢。 sendMailServlet代码: try { String host = “smtp.gmail.com”; String from = “my@gmail.com”; String pass = “pass”; Properties props = System.getProperties(); props.put(“mail.smtp.starttls.enable”, “true”); props.put(“mail.smtp.host”, host); props.put(“mail.smtp.user”, from); props.put(“mail.smtp.password”, pass); props.put(“mail.smtp.port”, “587”); props.put(“mail.smtp.auth”, “true”); props.put(“mail.debug”, “true”); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); Address fromAddress = new InternetAddress(from); […]

JavaMail Exchange身份validation

我正在尝试使用JavaMail从我的应用程序中使用Exchange身份validation来执行此操作。 有人可以给我一个指导吗? 身份validation后,我需要发送邮件,这是我使用JavaMail的主要原因。 我发现的所有链接都谈到了这方面的问题,但我认为这必须是一个简单的Java任务。 提前致谢。

JavaMail with Gmail:535-5.7.1不接受用户名和密码

当我尝试使用JavaMail API发送邮件时出现此错误。 我确信用户名和密码是100%正确的。 我正在连接的Gmail帐户是一个旧帐户,因为他们说它需要时间来处理新帐户。 DEBUG SMTP RCVD:535-5.7.1不接受用户名和密码。 了解更多信息 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 x35sm3011668 wfh.6 javax.mail.SendFailedException:发送失败; 嵌套exception是: javax.mail.AuthenticationFailedException 在javax.mail.Transport.send0(Transport.java:218) 在javax.mail.Transport.send(Transport.java:80) 在Main。(Main.java:41) 在Main.main(Main.java:51) 这是我的代码: import javax.mail。*; import javax.mail.internet。*; import java.util。*; 公共课主 { String d_email =“abc@gmail.com”, d_password =“通过”, d_host =“smtp.gmail.com”, d_port =“465”, m_to =“abc@gmail.com”, m_subject =“测试”, m_text =“测试电子邮件。”; 公共主要() { 属性props = new Properties(); props.put(“mail.smtp.user”,d_email); props.put(“mail.smtp.host”,d_host); props.put(“mail.smtp.port”,d_port); props.put( “mail.smtp.starttls.enable”, […]

ClassFormatError:在类文件javax / mail / MessagingException中非本机或抽象的方法中的Absent Code属性

当我使用javaMail api在我的spring mvc web应用程序上发送电子邮件时,我得到一个奇怪的ClassFormatError 。 下面是我的mail-cfg.xml true true 我的POM文件 4.0.0 FreedomSpring FreedomSpring war 0.0.1-SNAPSHOT org.apache.maven.plugins maven-compiler-plugin 3.0 1.5 1.5 org.apache.maven.plugins maven-war-plugin 2.3 WebContent src\main\webapp\WEB-INF\web.xml org.springframework spring-webmvc 3.1.2.RELEASE org.springframework spring-orm 3.1.2.RELEASE junit junit 4.10 net.sf.json-lib json-lib 2.4 jdk15 org.hibernate hibernate-core 4.1.7.Final jar compile org.hibernate hibernate-validator 4.3.0.Final log4j log4j 1.2.17 org.springframework spring-tx 3.1.2.RELEASE org.springframework spring-test 3.1.2.RELEASE commons-dbcp […]

最佳实践 – 发送javamail mime多部分电子邮件 – 和gmail

我有一个需要发送确认电子邮件等的Tomcat应用程序。我已经使用Javamail(mail.jar)编写了电子邮件编辑器,以发送多部分文本/ HTML电子邮件。 我将代码基于Java EE示例。 我在本地服务器上使用SMTP MTA。 它很棒。 在Outlook中,我看到了HTML版本。 如果我将其拖到Outlook垃圾邮件文件夹中,我会看到文本版本。 所以我解释说它有效。 但是,如果我在Gmail中查看电子邮件,我只会看到文字版本。 我知道HTML就在那里(这就是Outlook从中得到的)。 但Gmail没有显示它……我有很多来自其他系统的电子邮件,在Gmail中显示为HTML。 任何人都能指出我显示我失踪的规格吗? 我需要创建特殊标题吗? 谢谢 代码如下所示: Message message = new MimeMessage(session); Multipart multiPart = new MimeMultipart(“alternative”); try { MimeBodyPart textPart = new MimeBodyPart(); textPart.setText(text, “utf-8”); MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(html, “text/html; charset=utf-8”); multiPart.addBodyPart(htmlPart); multiPart.addBodyPart(textPart); message.setContent(multiPart); if(from != null){ message.setFrom(new InternetAddress(from)); }else message.setFrom(); if(replyto […]

执行JavaMail时,所有JFrame都会冻结

我开发汽车管理系统的程序。 然后,当汽车进来和开车时,我想发送邮件给这家公司的老板。 我的代码可以成功发送邮件,但我注意到,在邮件发送完成之前,当邮件发送时,其他JFrame窗口被冻结(我无法在所有JFrame窗口上执行任何操作)。 这通常适用于Javamail还是有办法使其他JFrame仍然有效? 在我的程序中,完成发送一封邮件大约需要10秒钟。

使用JavaMail在电子邮件中嵌入图像

我想使用javamail发送带有内嵌图像的电子邮件。 我正在做这样的事情。 MimeMultipart content = new MimeMultipart(“related”); BodyPart bodyPart = new MimeBodyPart(); bodyPart.setContent(message, “text/html; charset=ISO-8859-1”); content.addBodyPart(bodyPart); bodyPart = new MimeBodyPart(); DataSource ds = new ByteArrayDataSource(image, “image/jpeg”); bodyPart.setDataHandler(new DataHandler(ds)); bodyPart.setHeader(“Content-Type”, “image/jpeg; name=image.jpg”); bodyPart.setHeader(“Content-ID”, “”); bodyPart.setHeader(“Content-Disposition”, “inline”); content.addBodyPart(bodyPart); msg.setContent(content); 我也试过了 bodyPart.setHeader(“inline; filename=image.jpg”); 和 bodyPart.setDisposition(“inline”); 但无论如何,图像都作为附件发送,内容处理正在变成“附件”。 如何使用javamail在电子邮件中内联发送图像?

基于SSL的JavaMail IMAP非常慢 – 批量获取多条消息

我目前正在尝试使用JavaMail从IMAP服务器(Gmail和其他人)获取电子邮件。 基本上,我的代码工作:我确实可以得到标题,正文内容等。 我的问题如下:当处理IMAP服务器(没有SSL)时,处理消息基本上需要1-2ms。 当我使用IMAPS服务器(因此使用SSL,例如Gmail)时,我的消息达到250米左右。 我只测量处理消息的时间(不考虑连接,握手等)。 我知道因为这是SSL,所以数据是加密的。 但是,解密的时间应该不那么重要,是吗? 我已经尝试设置更高的ServerCacheSize值,更高的connectionpoolsize,但我的想法很严重。 谁有人遇到这个问题? 解决了一个人可能希望? 我担心JavaMail API每次从IMAPS服务器获取邮件时都会使用不同的连接(涉及握手的开销……)。 如果是这样,有没有办法覆盖这种行为? 这是从Main()类调用的代码(虽然非常标准): public static int connectTest(String SSL, String user, String pwd, String host) throws IOException, ProtocolException, GeneralSecurityException { Properties props = System.getProperties(); props.setProperty(“mail.store.protocol”, SSL); props.setProperty(“mail.imaps.ssl.trust”, host); props.setProperty(“mail.imaps.connectionpoolsize”, “10”); try { Session session = Session.getDefaultInstance(props, null); // session.setDebug(true); Store store = session.getStore(SSL); store.connect(host, user, […]