标签: jakarta-mail

用于JavaMail测试的邮件服务器

我想在本地测试JavaMail,所以我需要一个邮件服务器.我可以使用任何免费邮件服务器吗?

email jakarta-mail mail-server

10
推荐指数
4
解决办法
2万
查看次数

如何将javax.mail.Session setDebugOut重定向到log4j logger?

如何将javax.mail.Session setDebugOut重定向到log4j logger?

是否可以仅将mailSession调试重定向到记录器?

我的意思是,有类似的解决方案

链接文字

它将所有标准输出重新分配到log4j

--System.setOut(new Log4jStream())

最好的祝福

java email debugging log4j jakarta-mail

10
推荐指数
2
解决办法
6702
查看次数

以Pdf附件的形式发送电子邮件作为流

我想发送一个Pdf作为电子邮件附件(我正在使用JavaMail API).我有一个Pdf(由jasper生成)作为byte[].

public InputStream exportPdfToInputStream(User user) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, JRException, IOException{
        JasperPrint jasperPrint = createJasperPrintObject(user);
        byte[] pdfByteArray = JasperExportManager.exportReportToPdf(jasperPrint);
        return new ByteArrayInputStream(pdfByteArray);
    }
Run Code Online (Sandbox Code Playgroud)

这是我用来构建MimeBodyPart附件的代码:

    if (arrayInputStream != null && arrayInputStream instanceof ByteArrayInputStream) {
        MimeBodyPart attachment = new MimeBodyPart(arrayInputStream);
        attachment.setHeader("Content-Type", "application/pdf");
        mimeMultipart.addBodyPart(attachment);
    }
Run Code Online (Sandbox Code Playgroud)

这段代码给了我这个错误:

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    java.io.IOException: Error in encoded stream: needed at least 2 valid base64 characters, but only got 1 before padding character (=), the 10 most recent …
Run Code Online (Sandbox Code Playgroud)

java email jakarta-mail mime-types

10
推荐指数
2
解决办法
3万
查看次数

Java Mail:Session

下面用于连接和执行IMAP文件夹操作的代码.所以我的问题是关于javax.mail.Session在这种情况下每秒重建一次(取决于checkInbox()的休眠时间和运行时间).

我确信这不是一个好的解决方案,特别是对IMAP的调查有点愚蠢,但我无法IMAP listener运行.

不是每次运行都重新创建会话可能是一个更好的解决方案,但我怎么知道何时session is closed或是否可以故意关闭它?但是没有什么Session.close()比Session或者什么更像是NULL?或者会话上有一些已定义的超时...

来源:

final String port = "993";

Properties prop = new Properties();

// I assume there is some redundancy here but this didn't cause any problems so far
prop.setProperty("mail.imaps.starttls.enable", "true");
prop.setProperty("mail.imaps.port", port);

/** This part can be removed
 * prop.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
 * prop.setProperty("mail.imaps.socketFactory.port", port); 
 * prop.setProperty("mail.imaps.socketFactory.fallback", "false"); 
 */
prop.setProperty("mail.imap.ssl.enable", "true");
prop.setProperty("mail.debug", "false");

// Create a session before you loop since the configuration doesn't change
Session session …
Run Code Online (Sandbox Code Playgroud)

java email imap jakarta-mail

10
推荐指数
1
解决办法
1万
查看次数

JavaMail:Java.awt.datatransfer.Transferable 不存在

我不打算提出问题,但我没有解决这个问题!
我在从 IMAP 服务器接收消息时遇到问题。
错误说“由:java.lang.ClassNotFoundException:在路径上找不到类“java.awt.datatransfer.Transferable”......”这是我的代码:

enter String test(){
    String all="";
    try{
        class Runner extends AsyncTask<Object, String, String> {
            @Override
            protected String doInBackground(Object... params) {
                Looper.prepare();
                String all ="";
                try{
                    Message[] msgs = ReceiveMail("imap.gmail.com","993","USER@gmail.com","PASS"); // After passing this line, error logging says error is in this line!
                    for(Message m: msgs){
                        all+=m.getSubject()+"\n"+m.getContent().toString()+"\n\n"; // Error shows here, but popups above
                    }
                    return all;
                }catch (Exception e){
                    e.printStackTrace();
                }
                Looper.loop();
                return all;
            }
        }
        Runner r = new Runner();
        all = r.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this).get();
    }catch …
Run Code Online (Sandbox Code Playgroud)

java android jakarta-mail

10
推荐指数
2
解决办法
4945
查看次数

Office 365邮件收​​件箱文件夹EXPUNGE使用java邮件API与IMAP失败

我使用java邮件API与IMAP协议连接Office 365邮箱.

我们有连续的邮件流到邮箱,并通过java邮件API读取它们.读取邮件后,这些邮件将被移动到其他文件夹或删除.成功移动/删除批处理后,我正在对INBOX文件夹进行清除.

上述功能在72小时内表现良好,然后EXPUNGE命令不断失败.以下是观察到的例外情况

javax.mail.MessagingException:A447 NO EXPUNGE失败.嵌套异常是:com.sun.mail.iap.CommandFailedException:A447 NO EXPUNGE失败.at com.sun.mail.imap.IMAPFolder.expunge(IMAPFolder.java:2190)at com.si.mail.imap.IMAPFolder.expunge(IMAPFolder.java:2151)at com.eiq.socvportportal.securitymonitoring.incidents.feeder ..com.IncidentsMailboxReader.expungeConnectionInbox(IncidentsMailboxReader.java:423)位于com.eiq.socv.ports上的com.eiq.socvport.alcuritymonitoring.incidents.feeder.mail.IncidentsMailboxReader.updateCompletedConnection(IncidentsMailboxReader.java:311),来自com.eiq.socvportport.securitymonitoring.incidents.feeder ..com.IncidentsMailboxReader.checkAndUpdateConnectionInstances(IncidentsMailboxReader.java:285)位于com.eiq.socv.ports.securitymonitoring.itoridents.feeders.com的com.eiq.socvport.alcuritymonitoring.incidents.feeder.mail.IncidentsMailboxReader.getUnreadIncidentMails(IncidentsMailboxReader.java:76) .worker.IncidentMailsProcessor.findAndProcessUnreadMails(IncidentMailsProcessor.java:200),位于java.util的com.eiq.socvport.alcuritymonitoring.incidents.feeder.worker.IncidentMailsProcessor.run(IncidentMailsProcessor.java:85).concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:745)引起: com.sun.mail.iap.CommandFailedException:A447 NO EXPUNGE失败.at com.sun.mail.iap.Protocol.handleResult(Protocol.java:399)at com.sun.mail.iap.Protocol.simpleCommand(Protocol.java:425)at com.sun.mail.imap.protocol.IMAPProtocol .expunge(IMAPProtocol.java:1479)at com.sun.mail.imap.IMAPFolder.expunge(IMAPFolder.java:2183)... 10更多

如何避免这种情况?在什么情况下可以观察到这一点?

api imap jakarta-mail office365

10
推荐指数
1
解决办法
1214
查看次数

JavaMail:"域包含字符串中的控件或空格"错误消息,因为域有丹麦字符

现在允许使用具有特殊丹麦字符的域,例如æøå,但我不能强制java邮件接受此.

    @Test()
public void testMailAddressWithDanishCharacters1() throws AddressException, UnsupportedEncodingException {
    InternetAddress cAddress = new InternetAddress( "test@testæxample12345123.com", null, "utf-8" );
    System.out.println( cAddress.toString() );
    cAddress.validate();
}

@Test()
public void testMailAddressWithDanishCharacters2() throws AddressException, UnsupportedEncodingException {
    InternetAddress cAddress = new InternetAddress( "test@testæxample12345123.com", false );
    System.out.println( cAddress.toString() );
    cAddress.validate();
}

@Test()
public void testMailAddressWithDanishCharacters3() throws AddressException, UnsupportedEncodingException {
    InternetAddress cAddress = new InternetAddress( "test@testæxample12345123.com", true );
    System.out.println( cAddress.toString() );
    cAddress.validate();
}
Run Code Online (Sandbox Code Playgroud)

所有测试都在InternetAddress的构造函数或validate()方法中失败.如何在域中处理这些特殊的丹麦字符.我敢打赌其他国家/地区的域名与电子邮件在javamail InternetAddress中存在同样的问题.

java email dns jakarta-mail

9
推荐指数
1
解决办法
1万
查看次数

如何将inputstream转换为InputStreamsource或Datasource以在Spring JavaMail中附加

我正在从Jsch channelSFTP获取输入流,如下所示.

   ChannelSftp channelSftp = (ChannelSftp)channel;
   InputStream input=channelsftp.get(unixPath);//unixPath is path to my file which is on SFTP server
Run Code Online (Sandbox Code Playgroud)

我必须unixPath在Spring javaMail附件中附加该文件.但是,当我看到Spring JavaMail addAttachment()方法的API时,它只需要InputStreamSourceDatasource.我的问题是我不能够获得InputStreamSourceDatasource从中我得到的形式SFTP channel.How我可以得到InputStream的InputStreamSourceDatasource从上面的InputStream?提前致谢.

spring sftp inputstream jakarta-mail jsch

9
推荐指数
1
解决办法
2万
查看次数

如何使用DKIM签署Javamail

没有外部库,是否有图书馆或方法?我使用apache james作为我的邮件服务器,目前发送这样的电子邮件:

public void sendMessage(String to, String subject, String content) {
    MimeMessage message = new MimeMessage(session);
    try {
        message.addRecipients(Message.RecipientType.TO, to);
        message.setFrom(new InternetAddress(from));
        message.setSubject(subject);
        message.setContent(content, "text/html; charset=utf-8");
        Transport.send(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }       
}
Run Code Online (Sandbox Code Playgroud)

但我想事先用DKIM与电子邮件签名.我知道我需要在james服务器上实现DKIM签名并计划使用jDKIM来实现这一点,我也理解我需要使用像www.port25.com这样的东西来创建密钥,但是如何在java之前实际签署电子邮件我发了出去?

java email jakarta-mail james dkim

9
推荐指数
2
解决办法
9951
查看次数

MailConnectException:无法连接到主机,端口:smtp.gmail.com,465;超时 -1

我需要使用 Gmail 作为 SMTP 服务器从我的应用程序发送电子邮件。这是我的邮件连接器类,我在单独的属性文件中设置了值

    public class EmailConnector {


    public static Session sessionCreate() {
        final String fromEmail = ConfigurationManager.getInstance().getProperty(EmailConfig.SENDER_EMAIL.toString());

        final String password = ConfigurationManager.getInstance().getProperty(EmailConfig.SENDER_PASSWORD.toString());

        Properties props = new Properties();
        props.put("mail.smtp.host", ConfigurationManager.getInstance().getProperty(EmailConfig.SMTP_HOST.toString()));

        props.put("mail.smtp.socketFactory.port",
                ConfigurationManager.getInstance().getProperty(EmailConfig.SSL_PORT.toString()));

        props.put("mail.smtp.socketFactory.class",
                ConfigurationManager.getInstance().getProperty(EmailConfig.SSL_FACTORY_CLASS.toString()));

        props.put("mail.smtp.auth",
                ConfigurationManager.getInstance().getProperty(EmailConfig.SMTP_AUTHENTICATION.toString()));

        props.put("mail.smtp.port", ConfigurationManager.getInstance().getProperty(EmailConfig.SMTP_PORT.toString()));

        Authenticator auth = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(fromEmail, password);
            }
        };
        return Session.getDefaultInstance(props, auth);
    }
}
Run Code Online (Sandbox Code Playgroud)

特性:

#Email send configuration
SENDER_EMAIL = abcalerts@gmail.com
SENDER_PASSWORD = abcalert321
SMTP_HOST = smtp.gmail.com
SSL_PORT = 465
SMTP_AUTHENTICATION = true …
Run Code Online (Sandbox Code Playgroud)

jakarta-mail jakarta-ee

9
推荐指数
2
解决办法
6万
查看次数