Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

JavaMail vs Outlook

$
0
0

Trying to send an email with an attachment using JavaMail. If you view the letter through a browser, then everything works fine. If you view the letter through Outlook, the letter comes in the form of a file with the extension .dat. Tell me what is the problem? How can this be fixed?

My code

public class MailMail{

    private JavaMailSender mailSender;
    private SimpleMailMessage simpleMailMessage;

    public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {
        this.simpleMailMessage = simpleMailMessage;
    }

    public void setMailSender(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }

    void sendMAil4() throws EmailException {

        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath("C:\\Users\\home\\Desktop\\отправка\\file.xlsx");
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setDescription("Picture of John");
        attachment.setName("John");

        MultiPartEmail email = new MultiPartEmail();
        email.setHostName("smtp.yandex.ru");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("from@yandex.ru", "12345678"));
        email.setFrom("from@yandex.ru");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("to@yandex.ru");

        email.attach(attachment);

        email.send();

    }
}

Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>