我正在尝试send emails with javamail and a local smtp serveur (hMailServer)
。
你能否告诉我javmail是否是用java发送电子邮件的最佳方式?
然后我有一个错误告诉我=> 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);
}
}
}
Delivry和发件人地址是一样的,我试过像gmail或hotmail这样的其他地址仍然是同样的问题。
答案 0 :(得分:0)
JavaMail是使用Java发送电子邮件的最佳方式。
错误来自您的邮件服务器。它抱怨一个特定的收件人地址。您需要检查邮件服务器配置,以了解它为什么不允许您发送到该地址。它可能像you've failed to login to your mail server一样简单,因此它不知道您是谁,因此不会让您发送到该地址。 protocol trace会提供更多详细信息。
答案 1 :(得分:0)
当您使用javamail时,您在FROM字段中放置的地址必须是hmailServer中的现有帐户,即使服务器在物理上相同,如果在hMailServer中未创建FROM字段,则会出现此错误。
// The following account must be created in a hMailServer domain called qqq.com
message.setFrom(new InternetAddress("xxx@qqq.com"));