しようとしていsend emails with javamail and a local smtp serveur (hMailServer)
ます。javaで電子メールを送信するのにjavamailが最適な方法かどうか教えていただけますか?
それから私は私に言うエラーがあります=> 550配信はこのアドレスには許可されていません それがその形式なのか、それともそれ自体のアドレスなのかわかりません:
スタックトレース:
SEVERE: Erreur dans le message
SEVERE: javax.mail.SendFailedException: Invalid Addresses;<br>
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 Delivery is not allowed to this address.
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at dao.SendEmail.sendEmail(SendEmail.java:51)
at beans.ActionBean.ajouter(ActionBean.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
原因: com.sun.mail.smtp.SMTPAddressFailedException: 550 このアドレスへの配信は許可されていません。com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1686) で ... 45 以上
public void sendEmail(Action action) {
if (action.getCopieAction() != null) {
try {
Properties props = new Properties();
String host = "localhost";
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.from", "sakina@transat.fr");
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
UtilisateurDao user = new UtilisateurDao();
// récupération du code user de l'utilisateur
Integer codeUserEnCopie = action.getCopieAction();
System.out.println(codeUserEnCopie);
Utilisateur util = user.findUserByCode(91);
String mailUserCopie = util.getEmail();
System.out.println(mailUserCopie);
InternetAddress recipient = new InternetAddress(mailUserCopie);
message.setRecipient(Message.RecipientType.TO, recipient);
message.setSubject("Vous êtes en copie d'une action");
message.setText("Bonjour, l'utilisateur "
+ action.getUtilCreation()
+ " vous à mis en copie d'une action:"
+ "Nom de l'action : " + action.getObjetAction()
+ "Détails de l'action : " + action.getTexteAction()
+ "Date de l'action : " + action.getDateAction());
Transport.send(message);
} catch (NoSuchProviderException e) {
System.err
.println("Pas de transport disponible pour ce protocole");
System.err.println(e);
} catch (AddressException e) {
System.err.println("Adresse invalide");
System.err.println(e);
} catch (MessagingException e) {
System.err.println("Erreur dans le message");
System.err.println(e);
}
}
}
配信と送信者のアドレスは同じです。gmail や hotmail などの他のアドレスで試してみましたが、それでも同じ問題です。