#MimeMailMessage - message not delivery to e-mail

1 messages · Page 1 of 1 (latest)

normal orchid
#

Hi. I added MimeMailMessage for send message witch attachment, but when i test it, messages are not visible in my email... No exceptions or errors. I changed SimpleMailMessage to Mime because i want to attach .pdf files, but SimpleMailMessage works perfectly. Could anybody know why its not works?

charred basinBOT
#

<@&1004656351647117403> please have a look, thanks.

charred basinBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

normal orchid
#
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "smtp.gmail.com");

        String username = "hidden";
        String password = "hidden";

        properties.put("mail.smtp.port", 587);
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true");


        properties.put("mail.user", username);
        properties.put("mail.password", password);


        Authenticator auth = new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        };
        Session session = Session.getInstance(properties, auth);

        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setContent("I have some attachments for you", "text/html");


        Multipart multipart = new MimeMultipart();
            MimeBodyPart attachPart = new MimeBodyPart();

            try {
                attachPart.attachFile("C:\\orion\\xx.pdf");
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            multipart.addBodyPart(attachPart);

        // creates a new e-mail message
        Message msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress("hidden"));
        InternetAddress[] toAddresses = { new InternetAddress(toEmail) };
        msg.setRecipients(Message.RecipientType.TO, toAddresses);
        msg.setSubject(subject);
        msg.setSentDate(new Date());

        msg.setContent(multipart);

        // sends the e-mail
        Transport.send(msg);

    }```
charred basinBOT