0

I'm trying to send email using JNDI, but for some strange reason the from field is not set.

context.xml:

 <Resource name="email/user" 
    description="support email"
    auth="Container"
    type="javax.mail.Session"
    username="user@server.net"
    password="pass"
    mail.debug="false"
    mail.user="user@server.net"
    mail.from="user@server.net"
    mail.transport.protocol="smtp" 
    mail.host="mail.server.net"
    mail.smtp.host="mail.server.net"
    mail.smtp.auth="true"
    mail.smtp.from="user@server.net"
    mail.smtp.starttls.enable="true"
    mail.smtp.submitter="user@server.net"/>

And how I'm getting this to application:

Context ctx = new InitialContext();
Session userEmail = (Session) ctx.lookup("java:comp/env/email/user");

And everything is fine, but when I'm sending this email to some servers I receive return message: We can't accept your message - missing From: (#5.3.0)

Additional question:

How to set nice looking from? I tried this:

mail.from="company XYZ &lt;user@server.net&gt;"

But it doesn't work....

4

1 回答 1

2

我找到了原因。问题出在消息创建中。

我错过了message.setFrom();

代码:

Message message = new MimeMessage(mailSession);
message.setFrom(); //this was missing
message.setSubject(subject);
message.setContent(content, "text/html; charset=" + charset); 
//... set recipients, ....
Transport.send(message);

现在我的两个问题都得到了解答。“看起来不错”现在也在起作用。

于 2013-03-26T19:45:15.473 回答