Pregunta

I have following code. But in the email, I get the sender as "unknown sender". When the receiver is gmail and yahoo, the email is not received at all. I managed to receive the email from own domain mail box (set up in outlook) and also another company email address (different domain). In this two, sender email is shown but still in outlook when the email is received it says as "unknown sender" and the name is not shown.

enter image description here

Properties props = new Properties();
        props.put("mail.smtp.host", "mail.domain.com"));

    props.put("mail.smtp.auth","false"));
    props.put("mail.smtp.starttls.enable","false"));
    props.put("mail.smtp.port","25"));

    Session session = Session.getDefaultInstance(props);


    try {
        String subject = "Email Subject";
        MimeMessage message = new MimeMessage(session);
        message.setSender(new InternetAddress("no-reply@domain.com", "Sender Name"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(emailTo));
        message.setSubject(subject);
        String content = writer.toString();
        message.setContent(content, "text/html; charset=UTF-8");

        Transport.send(message);
        logger.debug ("Email sent");
        return true;
    }

There are no exceptions and and I get the log "Email sent"

I don't have a mail box. I want to send the email without sender, still in the email it should be displayed a sender name, as well as sender email address as "no-reply@domain.com"

Following is how it is displayed. I have white marked company sensitive data. domain.com is also mock domain. In the real application I use real domain but the result is same.

enter image description here

Why gmail and yahoo blocking my mail?

¿Fue útil?

Solución

Try using setFrom instead of setSender, viz:

message.setFrom(new InternetAddress("Sender Name" + "<" + "no-reply@domain.com" + ">"));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top