You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Thibaut <la...@ifrance.com> on 2006/04/11 15:33:27 UTC
send mail
hi,
I receive email on the port 25. I try to send email from the james
server (to confirm the reception).
I do :
Properties props = System.getProperties();
props.put("mail.smtp.host", "localhost");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(this.from));
InternetAddress adresTo = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, adresTo);
message.setSubject(subject);
message.setContent(content, "text/html");
javax.mail.Transport.send(message);
but this doesn't work.
I read http://james.apache.org/FAQ.html#3 but i can't figure out the
solution.
Can anyone help me ?
Thibaut
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: send mail
Posted by Thibaut <la...@ifrance.com>.
I wrote this code in the mailet and the mail i create goes to the root
processor then in the transport processor.
I've tried exactly this code :
Collection recipients = new ArrayList();
recipients.add("technique@cvdunet.com");
MailImpl newMail = new MailImpl("toto", new
MailAddress("technique@cvdunet.com"), recipients);
try {
newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress());
newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName());
} catch (java.net.UnknownHostException _) {
newMail.setRemoteAddr("127.0.0.1");
newMail.setRemoteHost("localhost");
}
and it doesn't work ...
Stefano Bagnara a écrit :
> Where did you write this code?
>
> To send a new mail from a mailet you simply have to use the
> getMailetContext().sendMail(newMail); where newMail is the new mail
> you want to write.
>
> MailImpl newMail = new MailImpl(<your preferred constructor>);
> I suggesto you to add this code after the newMail creation:
> try {
> newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress());
>
> newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName());
> } catch (java.net.UnknownHostException _) {
> newMail.setRemoteAddr("127.0.0.1");
> newMail.setRemoteHost("localhost");
> }
>
> Using getMailetContext().sendMail() the new mail is stored to the
> spool and James handle it like any other incoming mail. (Be sure you
> avoid loops using specific Matchers).
> If you set a specific State (setState) to the message before using
> sendMail then the mail will start from the processor with that name.
>
> Stefano
>
>
> Thibaut wrote:
>
>> hi,
>>
>> I receive email on the port 25. I try to send email from the james
>> server (to confirm the reception).
>>
>> I do :
>>
>> Properties props = System.getProperties();
>> props.put("mail.smtp.host", "localhost");
>> Session session = Session.getDefaultInstance(props,
>> null);
>> MimeMessage message = new MimeMessage(session);
>> message.setFrom(new InternetAddress(this.from));
>> InternetAddress adresTo = new InternetAddress(to);
>> message.addRecipient(Message.RecipientType.TO, adresTo);
>> message.setSubject(subject);
>> message.setContent(content, "text/html");
>> javax.mail.Transport.send(message);
>>
>>
>> but this doesn't work.
>> I read http://james.apache.org/FAQ.html#3 but i can't figure out the
>> solution.
>>
>> Can anyone help me ?
>>
>> Thibaut
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: send mail
Posted by Stefano Bagnara <ap...@bago.org>.
Where did you write this code?
To send a new mail from a mailet you simply have to use the
getMailetContext().sendMail(newMail); where newMail is the new mail you
want to write.
MailImpl newMail = new MailImpl(<your preferred constructor>);
I suggesto you to add this code after the newMail creation:
try {
newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress());
newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName());
} catch (java.net.UnknownHostException _) {
newMail.setRemoteAddr("127.0.0.1");
newMail.setRemoteHost("localhost");
}
Using getMailetContext().sendMail() the new mail is stored to the spool
and James handle it like any other incoming mail. (Be sure you avoid
loops using specific Matchers).
If you set a specific State (setState) to the message before using
sendMail then the mail will start from the processor with that name.
Stefano
Thibaut wrote:
> hi,
>
> I receive email on the port 25. I try to send email from the james
> server (to confirm the reception).
>
> I do :
>
> Properties props = System.getProperties();
> props.put("mail.smtp.host", "localhost");
> Session session = Session.getDefaultInstance(props, null);
> MimeMessage message = new MimeMessage(session);
> message.setFrom(new InternetAddress(this.from));
> InternetAddress adresTo = new InternetAddress(to);
> message.addRecipient(Message.RecipientType.TO, adresTo);
> message.setSubject(subject);
> message.setContent(content, "text/html");
> javax.mail.Transport.send(message);
>
>
> but this doesn't work.
> I read http://james.apache.org/FAQ.html#3 but i can't figure out the
> solution.
>
> Can anyone help me ?
>
> Thibaut
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org