2013-03-12 3 views
0

jboss seam을 사용하여 메일을 전송할 때 장애 조치 기능을 구현해야합니다. mail-service.xml에 두 개의 JNDINames를 구성하려고했습니다. 하지만 코드에서 두 번째 JNDI 이름을 설정하는 방법을 알지 못합니다. 또한 코드에서 smtp 호스트를 설정하는 방법을 알지 못합니다. MY 코드 :Jboss Seam 메일에 대한 장애 조치 구성

@Name("emailService") 
@AutoCreate 
public class EmailService { 
private static final Log logger = LogFactory.getLog(EmailService.class); 

@In(create = true) 
private Renderer renderer; 

@Asynchronous 
public void sendMessage(@Duration long delay, String template, 
     Object infoNeededForTemplate) { 
    MailSession mailSession = new MailSession(); 
    try { 
     Contexts.getEventContext().set("currentMail", infoNeededForTemplate); 
     renderer.render(template); 
     logger.info("Email send to " + ((Mail) infoNeededForTemplate).getToEmail()); 
    } catch (Exception e) { 
     logger.error("Error while sending mail: Message = " + e.getMessage()); 
     try { 
      renderer.render(template); 
      logger.info("Email send to " + ((Mail) infoNeededForTemplate).getToEmail()); 
     } catch (Exception e1) { 
      logger.error("Error while sending mail: Message = " + e1.getMessage()); 
     } 
    } 
} 

}

내 메일-service.xml : 중 내가 어떻게 & 사용이 JNDIs 또는 설정 SMTP 호스트 서버를 구성 할 수 있습니다에

<?xml version="1.0" encoding="UTF-8"?> 
<server> 
<mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> 
    <attribute name="JNDIName">java:/Mail</attribute> 
    <attribute name="User">nobody</attribute> 
    <attribute name="Password">password</attribute> 
    <attribute name="Configuration"> 
    <!-- A test configuration --> 
    <configuration> 
    <!-- Change to your mail server prototocol --> 
    <property name="mail.store.protocol" value="pop3"/> 
    <property name="mail.transport.protocol" value="smtp"/> 

    <!-- Change to the user who will receive mail --> 
    <property name="mail.user" value="nobody"/> 

    <!-- Change to the mail server --> 
    <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/> 

    <!-- Change to the SMTP gateway server --> 
    <property name="mail.smtp.host" value="HOST_1"/> 

    <!-- The mail server port --> 
    <property name="mail.smtp.port" value="25"/> 

    <!-- Change to the address mail will be from --> 
    <property name="mail.from" value="[email protected]"/> 

    <!-- Enable debugging output from the javamail classes --> 
    <property name="mail.debug" value="true"/> 
    <property name="mail.smtp.auth" value="false"/> 
    <property name="mail.smtp.starttls.enable" value="false"/> 
    </configuration> 
</attribute> 
<depends>jboss:service=Naming</depends> 
</mbean> 

<mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> 
<attribute name="JNDIName">java:/Mail1</attribute> 
<attribute name="User">nobody</attribute> 
<attribute name="Password">password</attribute> 
<attribute name="Configuration"> 
    <!-- A test configuration --> 
    <configuration> 
    <!-- Change to your mail server prototocol --> 
    <property name="mail.store.protocol" value="pop3"/> 
    <property name="mail.transport.protocol" value="smtp"/> 

    <!-- Change to the user who will receive mail --> 
    <property name="mail.user" value="nobody"/> 

    <!-- Change to the mail server --> 
    <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/> 

    <!-- Change to the SMTP gateway server --> 
    <property name="mail.smtp.host" value="HOST_2"/> 

    <!-- The mail server port --> 
    <property name="mail.smtp.port" value="25"/> 

    <!-- Change to the address mail will be from --> 
    <property name="mail.from" value="[email protected]"/> 

    <!-- Enable debugging output from the javamail classes --> 
    <property name="mail.debug" value="true"/> 
    <property name="mail.smtp.auth" value="false"/> 
    <property name="mail.smtp.starttls.enable" value="false"/> 


    </configuration> 
</attribute> 
<depends>jboss:service=Naming</depends> 
</mbean> 
</server> 

당신이 좀 도와 주실 래요 메일을 보내는 즉시 보내시겠습니까? 미리 감사드립니다.

감사합니다, Saurabh

답변

0

당신은 Transport.connect 방법에 명시 적으로 호스트 이름을 지정할 수 있습니다; 자세한 내용은 javadocs를 참조하십시오.

+0

답장을 보내 주셔서 감사합니다. 문제에서 언급했듯이 Javamail 기능을 사용하지 않고 Jboss Seam을 사용합니다. 그래서 저에게 Transport on the fly는 작동하지 않을 것입니다. 1. 기존 컨텍스트에 다른 JNDIName을 삽입하십시오. 2. 기존 컨텍스트에 대해 다른 호스트를 주입하십시오. Seam으로 Transport 객체를 사용할 수 있다면 몇 가지 예제를 게시 할 수 있습니까? 감사. – Saurabhcdt

+0

Seam에 대해 아무것도 모르기 때문에 JavaMail API 사용을 제한하는 방법을 모르겠습니다. –

+0

나는 아직도 대답을 찾고있다. 어느 하나가 도와 드릴까요 ??? – Saurabhcdt