简体   繁体   English

com.sun.mail.smtp.SMTPSendFailedException:541 5.4.1 内容被内部防火墙阻止

[英]com.sun.mail.smtp.SMTPSendFailedException: 541 5.4.1 Content blocked by Internal Firewall

I am getting 541 5.4.1 Content blocked by Internal Firewall exception when i am sending a email in java.当我在 java 中发送 email 时,我收到 541 5.4.1 内容被内部防火墙异常阻止。 I have to send a calendar event so i am using String buffer and appending the content, when iam setting the content and sending email, i am getting blocked by internet firewall.我必须发送一个日历事件,所以我使用字符串缓冲区并附加内容,当我设置内容并发送 email 时,我被互联网防火墙阻止了。 Below iam keeping the code.下面是我保留代码。

public void send(Appointment appointment, String host) throws Exception {

        try {

            Properties prop = new Properties();
            prop.put("mail.smtp.host", host);
            prop.put("mail.smtp.port", "25");
            prop.put("mail.smtp.auth", "false");
            prop.put("mail.smtp.starttls.enable", "false");

            Session session = Session.getDefaultInstance(prop, null);
            // Define message
            MimeMessage message = new MimeMessage(session);
            message.addHeaderLine("method=REQUEST");
            message.addHeaderLine("charset=UTF-8");
            message.addHeaderLine("component=VEVENT");

            String toMa = StringUtils.getCommaDelimitedStringfromStringList(appointment.getTo());
            String ccMa = StringUtils.getCommaDelimitedStringfromStringList(appointment.getCc());

            message.setFrom(new InternetAddress(appointment.getFrom()));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMa));
            message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(ccMa));
            message.setSubject(appointment.getSubject());
            message.setHeader("Content-class", "urn:content-classes:calendarmessage");

            String content = getICSString2(appointment, message);

            // Create the message part
            BodyPart messageBodyPart = new MimeBodyPart();

            // Fill the message
            messageBodyPart.setHeader("Content-Class", "urn:content-  
  classes:calendarmessage");
            messageBodyPart.setHeader("Content-ID", "calendar_message");
            messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(content, "text/calendar")));// very
                                                                                                                // important

            // Create a Multipart
            Multipart multipart = new MimeMultipart();

            // Add part one
            multipart.addBodyPart(messageBodyPart);

            // Put parts in message
            message.setContent(multipart);

            // send message
            Transport.send(message);
        }
        catch (MessagingException me) {
            me.printStackTrace();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

private String getICSString2(Appointment appointment, MimeMessage message) {

        StringBuilder str = new StringBuilder();

        str.append("BEGIN:VCALENDAR");
        str.append("PRODID: Asset View 2.0");
        str.append("METHOD:REQUEST");
        str.append("BEGIN:VEVENT");

        str.append("DTSTAMP:" + extracted(FORMATED_DATE_TIME, 0, null));

        if (appointment.isIsAllDayEvent()) {

            str.append("DTSTART;VALUE=DATE:" + extracted(FORMATED_DATE, 0, appointment.getStartDate()));
            str.append("DTEND;VALUE=DATE:" + extracted(FORMATED_DATE, 1, appointment.getStartDate()));

        }
        else {
            str.append("DTSTART;VALUE=DATE:" + extracted(FORMATED_DATE_TIME, 0, appointment.getStartDate()));
            str.append("DTEND;VALUE=DATE:" + extracted(FORMATED_DATE_TIME, 0, appointment.getEndDate()));
        }

        createRecurringEvents(appointment, str);
        str.append("LOCATION: " + appointment.getLocation());
        str.append(String.format("UID:%s", UUID.randomUUID().toString()));
        str.append(String.format("DESCRIPTION:%s", appointment.getContent()));
        str.append(String.format("X-ALT-DESC;FMTTYPE=text/html:%s", appointment.getContent()));
        str.append(String.format("SUMMARY:%s", appointment.getSubject()));
        str.append(String.format("ORGANIZER:MAILTO:%s", appointment.getFrom()));
        str.append(String.format("ATTENDEE;CN=\"%s\";RSVP=TRUE:mailto:%s",
                appointment.getTo().stream().findFirst().orElse(null),
                appointment.getTo().stream().findFirst().orElse(null)));
        str.append("X-MICROSOFT-CDO-BUSYSTATUS:FREE");

        str.append("BEGIN:VALARM");
        str.append("ACTION:DISPLAY");
        str.append("DESCRIPTION:REMINDER");
        str.append("TRIGGER:-P1D");
        str.append("END:VALARM");

        str.append("END:VEVENT");
        str.append("END:VCALENDAR");

        return str.toString();
    }
    

I solved the issue by properly setting the content string.我通过正确设置内容字符串解决了这个问题。

StringBuffer sb = new StringBuffer();

        StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n"+
        "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"+
        "VERSION:2.0\n" +
        "METHOD:REQUEST\n" +
        "BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:"+appointment.getTo().stream().findFirst().orElse(null)+"\n" +
        "ORGANIZER:MAILTO:"+appointment.getFrom()+"\n" +
        "DTSTART:"+extracted(FORMATED_DATE_TIME, 0, appointment.getStartDate())+"\n" +
        "DTEND:"+extracted(FORMATED_DATE, 1, appointment.getEndDate())+"\n" +
        "LOCATION:"+appointment.getLocation()+"\n" +
        "TRANSP:OPAQUE\n" +
        "SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E00800000000002FF466CE3AC5010000000000000000100\n" +
        " 000004377FE5C37984842BF9440448399EB02\n" +
        "DTSTAMP:"+extracted(FORMATED_DATE_TIME, 0, null)+"\n" +
        "CATEGORIES:Meeting\n" +
        "DESCRIPTION:"+appointment.getContent()+"\n" +
        "SUMMARY:"+appointment.getSubject()+"\n" +
        "PRIORITY:5\n" +
        "CLASS:PUBLIC\n" +
        "BEGIN:VALARM\n" +
        "TRIGGER:PT1440M\n" +
        "ACTION:DISPLAY\n" +
        "DESCRIPTION:Reminder\n" +
        "END:VALARM\n" +
        "END:VEVENT\n" +
        "END:VCALENDAR");
        
        return buffer.toString();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.sun.mail.smtp.SMTPSendFailedException Javamail - com.sun.mail.smtp.SMTPSendFailedException Javamail com.sun.mail.smtp.SMTPSendFailedException:530 5.7.1客户端未通过身份验证 - com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated MailSendException:失败的消息:com.sun.mail.smtp.SMTPSendFailedException - MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException 如何解决com.sun.mail.smtp.SMTPSendFailedException在Java中? - how to solve com.sun.mail.smtp.SMTPSendFailedException in java ? com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要身份验证(Java Mail) - com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required (Java Mail) Spring Boot 邮件发件人错误:com.sun.mail.smtp.SMTPSendFailedException - Error at Spring Boot mail sender: com.sun.mail.smtp.SMTPSendFailedException com.sun.mail.smtp.SMTPSendFailedException:452 4.4.5磁盘空间不足; 稍后再试 - com.sun.mail.smtp.SMTPSendFailedException: 452 4.4.5 Insufficient disk space; try again later 错误:com.sun.mail.smtp.SMTPSendFailedException:451 4.3.0 错误:队列文件写入错误 - Error: com.sun.mail.smtp.SMTPSendFailedException: 451 4.3.0 Error: queue file write error 如何解决 com.sun.mail.smtp.SMTPSendFailedException:554 Email 被拒绝 - How to resolve com.sun.mail.smtp.SMTPSendFailedException: 554 Email rejected com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令 - com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM