我正在努力send emails with javamail and a local smtp serveur (hMailServer)
。你能告诉我javamail是否是用java发送电子邮件的最佳方式吗?
然后我有一个错误告诉我=> 550 Delivery is not allowed to this address 我不明白这是它的格式还是它自己的地址:
堆栈跟踪:
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 仍然是同样的问题。