cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lionel Barth <lba...@hachette-livre.fr>
Subject Re: how to send email in cocoon
Date Wed, 14 Mar 2007 10:57:05 GMT
Hi,

I have been able to send email in cocoon with :

- actions :
 <map:components>
  <map:actions>
     <map:action name="sendmail" logger="sitemap.action.sendmail"
                  src="org.apache.cocoon.acting.Sendmail"/>
   ...
  </map:actions>
  ...
 </map:components>
  ...
          <map:match pattern="sendmail.xml">
            <map:act type="sendmail">
              <map:parameter name="from" value="{request-param:from}"/>
              <map:parameter name="to" value="{request-param:to}"/>
              <map:parameter name="subject" 
value="{request-param:subject}"/>
              <map:parameter name="charset" value="iso-8859-1"/>
              <map:parameter name="body" value="{request-param:body}"/>
              <map:redirect-to uri="getpub.xml?pub={request-param:pub}"/>
            </map:act>
          </map:match>

- xsp
          <map:match pattern="sendmail.xml">
            <map:generate type="serverpages" src="sendmail.xml"/>
            <map:transform type="encodeURL"/>
            <map:serialize/>
          </map:match>

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp"
          xmlns:sendmail="http://apache.org/cocoon/sendmail/1.0"
          xmlns:xsp-request="http://apache.org/xsp/request/2.0">
<page>
  <sendmail:send-mail>
    <sendmail:smtphost>smtpgr</sendmail:smtphost>
    <sendmail:smtpuser></sendmail:smtpuser>
    <sendmail:smtppassword></sendmail:smtppassword>
    <sendmail:charset>iso-8859-1</sendmail:charset>
    <sendmail:from><xsp-request:get-parameter name="from"/></sendmail:from>
    <sendmail:to><xsp-request:get-parameter name="to"/></sendmail:to>
    <sendmail:subject><xsp-request:get-parameter 
name="subject"/></sendmail:subject>
    <sendmail:body><xsp-request:get-parameter name="body"/></sendmail:body>
    <sendmail:on-success>
      <p>Email successfully sent.</p>
    </sendmail:on-success>
    <sendmail:on-error>
      <p style="color:red;">An error occurred: <sendmail:error-message/></p>
    </sendmail:on-error>
  </sendmail:send-mail>
</page>
</xsp:page>

- or flow script :
function sendmail(from, to, cc, subject, message){
  //Set the host smtp address
  var mailprops = new java.util.Properties();
  mailprops.put("mail.smtp.host", "smtpgr");
  // create some properties and get the default Session
  var session = javax.mail.Session.getDefaultInstance(mailprops, null);
  session.setDebug(false);
  // create a message
  var msg = new javax.mail.internet.MimeMessage(session);
  var addressFrom = new javax.mail.internet.InternetAddress(from);
  msg.setFrom(addressFrom);

  if ((to!=null) && (to!="")) {
    var temp = new Array();
    temp = to.split(',');
    for (var i = 0; i < temp.length; i++) {
      msg.addRecipient(javax.mail.Message.RecipientType.TO, new 
javax.mail.internet.InternetAddress(temp[i]));
    }
  }

  if ((cc!=null) && (cc!="")) {
    var temp = new Array();
    temp = cc.split(',');
    for (var i = 0; i < temp.length; i++) {
      msg.addRecipient(javax.mail.Message.RecipientType.CC, new 
javax.mail.internet.InternetAddress(temp[i]));
    }
  }

  // Optional : You can also set your custom headers in the Email if you 
Want
  //msg.addHeader("MyHeaderName", "myHeaderValue");
  // Setting the Subject and Content Type
  msg.setSubject(subject,"utf-8");
  msg.setText(message, "utf-8");
  msg.setSentDate(new java.util.Date());
  try
  {
   javax.mail.Transport.send(msg);
  }
  catch(e)
  {
   // failure
   cocoon.sendPage("failure.html");
   return;
  }
}

I am sorry I cannot give you the links to documentation, but my internet 
connection is currently broken.

Regards,
Lionel Barth

Bhavya Sharma a ecrit le 14/03/07 11:25:
> Hi everybody
>
> I have a problem how can i send email in cocoon however
> i have seen sendmail example in cocoon sample but it does not work i 
> know i should not mention this
> but its something urgent
>
> -- 
> Thanks
>
> Bhavya Sharma 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message