XML Feeds

.

[java-dev] net.mail.send

Owen Green owen at owengreen.net
Wed Dec 19 07:27:39 MST 2007


Hi Georg,

It's quite possible that the error is a consequence of not
authenticating, if that's what the SMTP server expects (the status of
response codes > 554 is sufficiently murky to not be clear with a quick
google, it seems).

Looking at the code for net.mail.send, hacking it to add authentication
shouldn't be massively difficult - there are broadly two ways, see:

<http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html>
<quote>
> To use SMTP authentication you'll need to set the mail.smtp.auth
> property (see below) and provide the SMTP Transport with a username
> and password when connecting to the SMTP server. You can do this
> using one of the following approaches:
> 
> * Provide an Authenticator object when creating your mail Session and
> provide the username and password information during the
> Authenticator callback.
> 
> Note that the mail.smtp.user property can be set to provide a default
> username for the callback, but the password will still need to be
> supplied explicitly.
> 
> This approach allows you to use the static Transport send method to
> send messages.
> 
> * Call the Transport connect method explicitly with username and
> password arguments.
> 
> This approach requires you to explicitly manage a Transport object
> and use the Transport sendMessage method to send the message. The
> transport.java demo program demonstrates how to manage a Transport
> object. The following is roughly equivalent to the static Transport
> send method, but supplies the needed username and password:
 >
>           Transport tr = session.getTransport("smtp");
>           tr.connect(smtphost, username, password);
>           msg.saveChanges();      // don't forget this
>           tr.sendMessage(msg, msg.getAllRecipients());
>           tr.close();
</quote>

hth,
Owen

Georg Hajdu wrote:
> I'm having trouble with net.mail.send. Trying to send email from/to
> my .mac account I'm getting this error message:
> 
> com.sun.mail.smtp.SMTPSendFailedException: 556 5.1.0 Invalid From
> header. at 
> com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
>  at
> com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321) 
> at
> com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637) 
> at javax.mail.Transport.send0(Transport.java:189) at
> javax.mail.Transport.send(Transport.java:118) at
> net.mail.send.deliver(send.java:71) exception: MessagingException
> 
> I have no idea why georghajdu at mac.com is generating this message. 
> Also, I noticed that authentication wasn't implemented. Is this on
> the author's to-do list? This would be nice!
> 
> I'm using JavaMail 1.4.1 and jaf 1.1.1 on a MacBook with 10.4.11 and
> the latest Java release installed.
> 
> Georg
> 
> 
> _______________________________________________ java-dev mailing list
>  java-dev at cycling74.com 
> http://www.cycling74.com/mailman/listinfo/java-dev
> 




More information about the java-dev mailing list