Attach File to E-mail (SMTP)

View: New views
9 Messages — Rating Filter:   Alert me  

Attach File to E-mail (SMTP)

by VinithGowda :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All, I would like to attach a file to the mail sending through SMTP connector,which is the best way doing it. Thanks in Advance, Vinith Gowda.

RE: Attach File to E-mail (SMTP)

by Wayne Wundram :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I created a Transformer that takes the content of the message and attaches it to an email. The code of my transformer is:

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

package miraculum.mule;

 

import java.io.IOException;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import org.apache.log4j.Logger;

import org.mule.transformers.AbstractTransformer;

import org.mule.umo.transformer.TransformerException;

import org.mule.util.DateUtils;

 

/**

 *

 * @author Wayne Wundram

 *

 *  Mule Transformer to take the contents of a Mail Message

 *  and send it as an attachment.

 *

 */

public class TfmMailContentsToAttachment extends AbstractTransformer {

    private String attachmentName;

    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss.SSS";

 

    static Logger log = Logger.getLogger(TfmMailContentsToAttachment.class.getName());

 

    public TfmMailContentsToAttachment() {

        super();

        this.registerSourceType(Message.class);

        this.setReturnClass(Message.class);

    }

 

    public Object doTransform(Object src, String encoding) throws TransformerException {

 

        MimeMessage inputMessage = (MimeMessage) src;

 

        // If the attachmentName property is not set then default it. 

        if (getAttachmentName() == null) {

            setAttachmentName("attachment.txt");

        }

        String generatedName = getAttachmentName();

        if (generatedName.indexOf("{DATE}") > -1) {

            String currentDate = DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);

            generatedName = generatedName.replace("{DATE}", currentDate);

            setAttachmentName(generatedName);

        }

         

        // Move content to an attachment.

        try {

            MimeBodyPart mimeBodyPart = new MimeBodyPart();

            mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getContentType());

            mimeBodyPart.setFileName(getAttachmentName());

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(mimeBodyPart);

            inputMessage.setContent(multipart);

 

        } catch (IOException ioe) {

            log.error("IOException " + ioe.getMessage());

            throw new TransformerException(this, ioe);

        } catch (MessagingException me) {

            log.error("MessagingException " + me.getMessage());

            throw new TransformerException(this, me);

 

        }

        return inputMessage;

    }

 

    public String getAttachmentName() {

        return attachmentName;

    }

 

    public void setAttachmentName(String attachmentName) {

        this.attachmentName = attachmentName;

    }

}

 

 

I used it in my config file as follows:

 

            <transformer name="GGMailContentsToAttachment"

                  className="miraculum.mule.TfmMailContentsToAttachment"

                  returnClass="javax.mail.Message">

                  <properties>

                        <property name="attachmentName" value="GA01-{DATE}.txt" />

                  </properties>

            </transformer>

 

Regards,

Wayne Wundram

 


From: VinithGowda [mailto:vinith.hr@...]
Sent: Friday, July 04, 2008 7:16 AM
To: user@...
Subject: [mule-user] Attach File to E-mail (SMTP)

 

Hi All, I would like to attach a file to the mail sending through SMTP connector,which is the best way doing it. Thanks in Advance, Vinith Gowda.


View this message in context: Attach File to E-mail (SMTP)
Sent from the Mule - User mailing list archive at Nabble.com.


RE: Attach File to E-mail (SMTP)

by VinithGowda :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Wayne Wundram,

Can u provide me the entire config.xml

Vinith Gowda.
Wayne Wundram wrote:
I created a Transformer that takes the content of the message and
attaches it to an email. The code of my transformer is:

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

package miraculum.mule;

 

import java.io.IOException;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import org.apache.log4j.Logger;

import org.mule.transformers.AbstractTransformer;

import org.mule.umo.transformer.TransformerException;

import org.mule.util.DateUtils;

 

/**

 *

 * @author Wayne Wundram

 *

 *  Mule Transformer to take the contents of a Mail Message

 *  and send it as an attachment.

 *

 */

public class TfmMailContentsToAttachment extends AbstractTransformer {

    private String attachmentName;

    public static final String DEFAULT_DATE_FORMAT =
"yyyy-MM-dd_HH-mm-ss.SSS";

 

    static Logger log =
Logger.getLogger(TfmMailContentsToAttachment.class.getName());

 

    public TfmMailContentsToAttachment() {

        super();

        this.registerSourceType(Message.class);

        this.setReturnClass(Message.class);

    }

 

    public Object doTransform(Object src, String encoding) throws
TransformerException {

 

        MimeMessage inputMessage = (MimeMessage) src;

 

        // If the attachmentName property is not set then default it.  

        if (getAttachmentName() == null) {

            setAttachmentName("attachment.txt");

        }

        String generatedName = getAttachmentName();

        if (generatedName.indexOf("{DATE}") > -1) {

            String currentDate =
DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);

            generatedName = generatedName.replace("{DATE}",
currentDate);

            setAttachmentName(generatedName);

        }

         

        // Move content to an attachment.

        try {

            MimeBodyPart mimeBodyPart = new MimeBodyPart();

 
mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getConten
tType());

            mimeBodyPart.setFileName(getAttachmentName());

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(mimeBodyPart);

            inputMessage.setContent(multipart);

 

        } catch (IOException ioe) {

            log.error("IOException " + ioe.getMessage());

            throw new TransformerException(this, ioe);

        } catch (MessagingException me) {

            log.error("MessagingException " + me.getMessage());

            throw new TransformerException(this, me);

 

        }

        return inputMessage;

    }

 

    public String getAttachmentName() {

        return attachmentName;

    }

 

    public void setAttachmentName(String attachmentName) {

        this.attachmentName = attachmentName;

    }

}

 

 

I used it in my config file as follows:

 

            <transformer name="GGMailContentsToAttachment"

                  className="miraculum.mule.TfmMailContentsToAttachment"

                  returnClass="javax.mail.Message">

                  <properties>

                        <property name="attachmentName"
value="GA01-{DATE}.txt" />

                  </properties>

            </transformer>

 

Regards,

Wayne Wundram

 

________________________________

From: VinithGowda [mailto:vinith.hr@i-logicon.co.in]
Sent: Friday, July 04, 2008 7:16 AM
To: user@mule.codehaus.org
Subject: [mule-user] Attach File to E-mail (SMTP)

 

Hi All, I would like to attach a file to the mail sending through SMTP
connector,which is the best way doing it. Thanks in Advance, Vinith
Gowda.

________________________________

View this message in context: Attach File to E-mail (SMTP)
<http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p18272
975.html>
Sent from the Mule - User mailing list archive
<http://www.nabble.com/Mule---User-f2727.html>  at Nabble.com.

RE: Attach File to E-mail (SMTP)

by antoine.borg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi,
 
Wayne, that's a great solution and an excellent mechanism to be able to add an attachment to a Mule message that is going to be an e-mail. 
 
If you, or Vinith, are interested in a transformer that will add attachments to a Mule message but which is not dependent upon SMTP, take a look at my series of posts about this topic starting here: http://ricston.com/blog/?p=26
I blogged about creating a transformer that adds attachments to messages which can then be used wherever attachments are valid (like SOAP for instance).
 
Regards
 
A
 
Antoine Borg, Senior Consultant | Tel: +356 21334457 | Fax: +356 21 334156
ricston Ltd., Lincoln, 7 Ferdinand Grech Street, Lija LJA1142, MALTA
email: antoine.borgantoine.borg@... | blog: blog.ricston.com | web: ricston.com 
 


From: Wayne Wundram [mailto:waynew@...]
Sent: Friday, July 04, 2008 7:34 AM
To: user@...
Subject: RE: [mule-user] Attach File to E-mail (SMTP)

I created a Transformer that takes the content of the message and attaches it to an email. The code of my transformer is:

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

package miraculum.mule;

 

import java.io.IOException;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import org.apache.log4j.Logger;

import org.mule.transformers.AbstractTransformer;

import org.mule.umo.transformer.TransformerException;

import org.mule.util.DateUtils;

 

/**

 *

 * @author Wayne Wundram

 *

 *  Mule Transformer to take the contents of a Mail Message

 *  and send it as an attachment.

 *

 */

public class TfmMailContentsToAttachment extends AbstractTransformer {

    private String attachmentName;

    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss.SSS";

 

    static Logger log = Logger.getLogger(TfmMailContentsToAttachment.class.getName());

 

    public TfmMailContentsToAttachment() {

        super();

        this.registerSourceType(Message.class);

        this.setReturnClass(Message.class);

    }

 

    public Object doTransform(Object src, String encoding) throws TransformerException {

 

        MimeMessage inputMessage = (MimeMessage) src;

 

        // If the attachmentName property is not set then default it. 

        if (getAttachmentName() == null) {

            setAttachmentName("attachment.txt");

        }

        String generatedName = getAttachmentName();

        if (generatedName.indexOf("{DATE}") > -1) {

            String currentDate = DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);

            generatedName = generatedName.replace("{DATE}", currentDate);

            setAttachmentName(generatedName);

        }

         

        // Move content to an attachment.

        try {

            MimeBodyPart mimeBodyPart = new MimeBodyPart();

            mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getContentType());

            mimeBodyPart.setFileName(getAttachmentName());

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(mimeBodyPart);

            inputMessage.setContent(multipart);

 

        } catch (IOException ioe) {

            log.error("IOException " + ioe.getMessage());

            throw new TransformerException(this, ioe);

        } catch (MessagingException me) {

            log.error("MessagingException " + me.getMessage());

            throw new TransformerException(this, me);

 

        }

        return inputMessage;

    }

 

    public String getAttachmentName() {

        return attachmentName;

    }

 

    public void setAttachmentName(String attachmentName) {

        this.attachmentName = attachmentName;

    }

}

 

 

I used it in my config file as follows:

 

            <transformer name="GGMailContentsToAttachment"

                  className="miraculum.mule.TfmMailContentsToAttachment"

                  returnClass="javax.mail.Message">

                  <properties>

                        <property name="attachmentName" value="GA01-{DATE}.txt" />

                  </properties>

            </transformer>

 

Regards,

Wayne Wundram

 


From: VinithGowda [mailto:vinith.hr@...]
Sent: Friday, July 04, 2008 7:16 AM
To: user@...
Subject: [mule-user] Attach File to E-mail (SMTP)

 

Hi All, I would like to attach a file to the mail sending through SMTP connector,which is the best way doing it. Thanks in Advance, Vinith Gowda.


View this message in context: Attach File to E-mail (SMTP)
Sent from the Mule - User mailing list archive at Nabble.com.


RE: Attach File to E-mail (SMTP)

by VinithGowda :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To be more clear with you I am using Mule 2.x

Thanks
Vinith Gowda
Wayne Wundram wrote:
I created a Transformer that takes the content of the message and
attaches it to an email. The code of my transformer is:

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

package miraculum.mule;

 

import java.io.IOException;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import org.apache.log4j.Logger;

import org.mule.transformers.AbstractTransformer;

import org.mule.umo.transformer.TransformerException;

import org.mule.util.DateUtils;

 

/**

 *

 * @author Wayne Wundram

 *

 *  Mule Transformer to take the contents of a Mail Message

 *  and send it as an attachment.

 *

 */

public class TfmMailContentsToAttachment extends AbstractTransformer {

    private String attachmentName;

    public static final String DEFAULT_DATE_FORMAT =
"yyyy-MM-dd_HH-mm-ss.SSS";

 

    static Logger log =
Logger.getLogger(TfmMailContentsToAttachment.class.getName());

 

    public TfmMailContentsToAttachment() {

        super();

        this.registerSourceType(Message.class);

        this.setReturnClass(Message.class);

    }

 

    public Object doTransform(Object src, String encoding) throws
TransformerException {

 

        MimeMessage inputMessage = (MimeMessage) src;

 

        // If the attachmentName property is not set then default it.  

        if (getAttachmentName() == null) {

            setAttachmentName("attachment.txt");

        }

        String generatedName = getAttachmentName();

        if (generatedName.indexOf("{DATE}") > -1) {

            String currentDate =
DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);

            generatedName = generatedName.replace("{DATE}",
currentDate);

            setAttachmentName(generatedName);

        }

         

        // Move content to an attachment.

        try {

            MimeBodyPart mimeBodyPart = new MimeBodyPart();

 
mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getConten
tType());

            mimeBodyPart.setFileName(getAttachmentName());

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(mimeBodyPart);

            inputMessage.setContent(multipart);

 

        } catch (IOException ioe) {

            log.error("IOException " + ioe.getMessage());

            throw new TransformerException(this, ioe);

        } catch (MessagingException me) {

            log.error("MessagingException " + me.getMessage());

            throw new TransformerException(this, me);

 

        }

        return inputMessage;

    }

 

    public String getAttachmentName() {

        return attachmentName;

    }

 

    public void setAttachmentName(String attachmentName) {

        this.attachmentName = attachmentName;

    }

}

 

 

I used it in my config file as follows:

 

            <transformer name="GGMailContentsToAttachment"

                  className="miraculum.mule.TfmMailContentsToAttachment"

                  returnClass="javax.mail.Message">

                  <properties>

                        <property name="attachmentName"
value="GA01-{DATE}.txt" />

                  </properties>

            </transformer>

 

Regards,

Wayne Wundram

 

________________________________

From: VinithGowda [mailto:vinith.hr@i-logicon.co.in]
Sent: Friday, July 04, 2008 7:16 AM
To: user@mule.codehaus.org
Subject: [mule-user] Attach File to E-mail (SMTP)

 

Hi All, I would like to attach a file to the mail sending through SMTP
connector,which is the best way doing it. Thanks in Advance, Vinith
Gowda.

________________________________

View this message in context: Attach File to E-mail (SMTP)
<http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p18272
975.html>
Sent from the Mule - User mailing list archive
<http://www.nabble.com/Mule---User-f2727.html>  at Nabble.com.

RE: Attach File to E-mail (SMTP)

by Wayne Wundram :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Vinith,

Sorry, these are for version 1.4.3. Here is the excerpt of the config
file that emails the attachment.

                <mule-descriptor name="GGEmailOrders"
       
implementation="org.mule.components.simple.PassThroughComponent">
                        <inbound-router>
                                <endpoint
address="vm://gargoyle.orders.email" />
                        </inbound-router>
                        <outbound-router>
                                <router
       
className="org.mule.routing.outbound.OutboundPassThroughRouter">
                                        <endpoint
       
address="smtp://${smtp.host}?address=${salesorder.toAddress}"
       
transformers="ObjectToEmailMessage GGMailContentsToAttachment" />
                                </router>
                        </outbound-router>
                </mule-descriptor>

Regards,
Wayne Wundram


-----Original Message-----
From: VinithGowda [mailto:vinith.hr@...]
Sent: Friday, July 04, 2008 8:48 AM
To: user@...
Subject: RE: [mule-user] Attach File to E-mail (SMTP)


To be more clear with you I am using Mule 2.x

Thanks
Vinith Gowda

Wayne Wundram wrote:

>
> I created a Transformer that takes the content of the message and
> attaches it to an email. The code of my transformer is:
>
>  
>
> /*
>
>  * To change this template, choose Tools | Templates
>
>  * and open the template in the editor.
>
>  */
>
>  
>
> package miraculum.mule;
>
>  
>
> import java.io.IOException;
>
> import javax.mail.Message;
>
> import javax.mail.MessagingException;
>
> import javax.mail.Multipart;
>
> import javax.mail.internet.MimeBodyPart;
>
> import javax.mail.internet.MimeMessage;
>
> import javax.mail.internet.MimeMultipart;
>
> import org.apache.log4j.Logger;
>
> import org.mule.transformers.AbstractTransformer;
>
> import org.mule.umo.transformer.TransformerException;
>
> import org.mule.util.DateUtils;
>
>  
>
> /**
>
>  *
>
>  * @author Wayne Wundram
>
>  *
>
>  *  Mule Transformer to take the contents of a Mail Message
>
>  *  and send it as an attachment.
>
>  *
>
>  */
>
> public class TfmMailContentsToAttachment extends AbstractTransformer {
>
>     private String attachmentName;
>
>     public static final String DEFAULT_DATE_FORMAT =
> "yyyy-MM-dd_HH-mm-ss.SSS";
>
>  
>
>     static Logger log =
> Logger.getLogger(TfmMailContentsToAttachment.class.getName());
>
>  
>
>     public TfmMailContentsToAttachment() {
>
>         super();
>
>         this.registerSourceType(Message.class);
>
>         this.setReturnClass(Message.class);
>
>     }
>
>  
>
>     public Object doTransform(Object src, String encoding) throws
> TransformerException {
>
>  
>
>         MimeMessage inputMessage = (MimeMessage) src;
>
>  
>
>         // If the attachmentName property is not set then default it.

>
>         if (getAttachmentName() == null) {
>
>             setAttachmentName("attachment.txt");
>
>         }
>
>         String generatedName = getAttachmentName();
>
>         if (generatedName.indexOf("{DATE}") > -1) {
>
>             String currentDate =
> DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);
>
>             generatedName = generatedName.replace("{DATE}",
> currentDate);
>
>             setAttachmentName(generatedName);
>
>         }
>
>          
>
>         // Move content to an attachment.
>
>         try {
>
>             MimeBodyPart mimeBodyPart = new MimeBodyPart();
>
>  
>
mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getConten

> tType());
>
>             mimeBodyPart.setFileName(getAttachmentName());
>
>             Multipart multipart = new MimeMultipart();
>
>             multipart.addBodyPart(mimeBodyPart);
>
>             inputMessage.setContent(multipart);
>
>  
>
>         } catch (IOException ioe) {
>
>             log.error("IOException " + ioe.getMessage());
>
>             throw new TransformerException(this, ioe);
>
>         } catch (MessagingException me) {
>
>             log.error("MessagingException " + me.getMessage());
>
>             throw new TransformerException(this, me);
>
>  
>
>         }
>
>         return inputMessage;
>
>     }
>
>  
>
>     public String getAttachmentName() {
>
>         return attachmentName;
>
>     }
>
>  
>
>     public void setAttachmentName(String attachmentName) {
>
>         this.attachmentName = attachmentName;
>
>     }
>
> }
>
>  
>
>  
>
> I used it in my config file as follows:
>
>  
>
>             <transformer name="GGMailContentsToAttachment"
>
>
className="miraculum.mule.TfmMailContentsToAttachment"

>
>                   returnClass="javax.mail.Message">
>
>                   <properties>
>
>                         <property name="attachmentName"
> value="GA01-{DATE}.txt" />
>
>                   </properties>
>
>             </transformer>
>
>  
>
> Regards,
>
> Wayne Wundram
>
>  
>
> ________________________________
>
> From: VinithGowda [mailto:vinith.hr@...]
> Sent: Friday, July 04, 2008 7:16 AM
> To: user@...
> Subject: [mule-user] Attach File to E-mail (SMTP)
>
>  
>
> Hi All, I would like to attach a file to the mail sending through SMTP
> connector,which is the best way doing it. Thanks in Advance, Vinith
> Gowda.
>
> ________________________________
>
> View this message in context: Attach File to E-mail (SMTP)
>
<http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p18272
> 975.html>
> Sent from the Mule - User mailing list archive
> <http://www.nabble.com/Mule---User-f2727.html>  at Nabble.com.
>
>
>

--
View this message in context:
http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p182738
51.html
Sent from the Mule - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Attach File to E-mail (SMTP)

by bokc bokc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I saw you use a ObjectToEmailMessage transformer. It is possible to get source code or some explication like output object type, parameters of this object,...?

Thanks,

Youkoun

2008/7/7 Wayne Wundram <waynew@...>:
Dear Vinith,

Sorry, these are for version 1.4.3. Here is the excerpt of the config
file that emails the attachment.

               <mule-descriptor name="GGEmailOrders"

implementation="org.mule.components.simple.PassThroughComponent">
                       <inbound-router>
                               <endpoint
address="vm://gargoyle.orders.email" />
                       </inbound-router>
                       <outbound-router>
                               <router

className="org.mule.routing.outbound.OutboundPassThroughRouter">
                                       <endpoint

address="smtp://${smtp.host}?address=${salesorder.toAddress}"

transformers="ObjectToEmailMessage GGMailContentsToAttachment" />
                               </router>
                       </outbound-router>
               </mule-descriptor>

Regards,
Wayne Wundram


-----Original Message-----
From: VinithGowda [mailto:vinith.hr@...]
Sent: Friday, July 04, 2008 8:48 AM
To: user@...
Subject: RE: [mule-user] Attach File to E-mail (SMTP)


To be more clear with you I am using Mule 2.x

Thanks
Vinith Gowda

Wayne Wundram wrote:
>
> I created a Transformer that takes the content of the message and
> attaches it to an email. The code of my transformer is:
>
>
>
> /*
>
>  * To change this template, choose Tools | Templates
>
>  * and open the template in the editor.
>
>  */
>
>
>
> package miraculum.mule;
>
>
>
> import java.io.IOException;
>
> import javax.mail.Message;
>
> import javax.mail.MessagingException;
>
> import javax.mail.Multipart;
>
> import javax.mail.internet.MimeBodyPart;
>
> import javax.mail.internet.MimeMessage;
>
> import javax.mail.internet.MimeMultipart;
>
> import org.apache.log4j.Logger;
>
> import org.mule.transformers.AbstractTransformer;
>
> import org.mule.umo.transformer.TransformerException;
>
> import org.mule.util.DateUtils;
>
>
>
> /**
>
>  *
>
>  * @author Wayne Wundram
>
>  *
>
>  *  Mule Transformer to take the contents of a Mail Message
>
>  *  and send it as an attachment.
>
>  *
>
>  */
>
> public class TfmMailContentsToAttachment extends AbstractTransformer {
>
>     private String attachmentName;
>
>     public static final String DEFAULT_DATE_FORMAT =
> "yyyy-MM-dd_HH-mm-ss.SSS";
>
>
>
>     static Logger log =
> Logger.getLogger(TfmMailContentsToAttachment.class.getName());
>
>
>
>     public TfmMailContentsToAttachment() {
>
>         super();
>
>         this.registerSourceType(Message.class);
>
>         this.setReturnClass(Message.class);
>
>     }
>
>
>
>     public Object doTransform(Object src, String encoding) throws
> TransformerException {
>
>
>
>         MimeMessage inputMessage = (MimeMessage) src;
>
>
>
>         // If the attachmentName property is not set then default it.

>
>         if (getAttachmentName() == null) {
>
>             setAttachmentName("attachment.txt");
>
>         }
>
>         String generatedName = getAttachmentName();
>
>         if (generatedName.indexOf("{DATE}") > -1) {
>
>             String currentDate =
> DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);
>
>             generatedName = generatedName.replace("{DATE}",
> currentDate);
>
>             setAttachmentName(generatedName);
>
>         }
>
>
>
>         // Move content to an attachment.
>
>         try {
>
>             MimeBodyPart mimeBodyPart = new MimeBodyPart();
>
>
>
mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getConten
> tType());
>
>             mimeBodyPart.setFileName(getAttachmentName());
>
>             Multipart multipart = new MimeMultipart();
>
>             multipart.addBodyPart(mimeBodyPart);
>
>             inputMessage.setContent(multipart);
>
>
>
>         } catch (IOException ioe) {
>
>             log.error("IOException " + ioe.getMessage());
>
>             throw new TransformerException(this, ioe);
>
>         } catch (MessagingException me) {
>
>             log.error("MessagingException " + me.getMessage());
>
>             throw new TransformerException(this, me);
>
>
>
>         }
>
>         return inputMessage;
>
>     }
>
>
>
>     public String getAttachmentName() {
>
>         return attachmentName;
>
>     }
>
>
>
>     public void setAttachmentName(String attachmentName) {
>
>         this.attachmentName = attachmentName;
>
>     }
>
> }
>
>
>
>
>
> I used it in my config file as follows:
>
>
>
>             <transformer name="GGMailContentsToAttachment"
>
>
className="miraculum.mule.TfmMailContentsToAttachment"
>
>                   returnClass="javax.mail.Message">
>
>                   <properties>
>
>                         <property name="attachmentName"
> value="GA01-{DATE}.txt" />
>
>                   </properties>
>
>             </transformer>
>
>
>
> Regards,
>
> Wayne Wundram
>
>
>
> ________________________________
>
> From: VinithGowda [mailto:vinith.hr@...]
> Sent: Friday, July 04, 2008 7:16 AM
> To: user@...
> Subject: [mule-user] Attach File to E-mail (SMTP)
>
>
>
> Hi All, I would like to attach a file to the mail sending through SMTP
> connector,which is the best way doing it. Thanks in Advance, Vinith
> Gowda.
>
> ________________________________
>
> View this message in context: Attach File to E-mail (SMTP)
>
<http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p18272
> 975.html>
> Sent from the Mule - User mailing list archive
> <http://www.nabble.com/Mule---User-f2727.html>  at Nabble.com.
>
>
>

--
View this message in context:
http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p182738
51.html

Sent from the Mule - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




RE: Attach File to E-mail (SMTP)

by Wayne Wundram :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Dear Youkoun,

 

ObjectToEmailMessages is a standard Mule transformer:

 

            <transformer name="ObjectToEmailMessage"

                  className="org.mule.providers.email.transformers.ObjectToMimeMessage"

                  returnClass="javax.mail.Message" />

 

Regards,

Wayne Wundram

Miraculum

South Africa

 


From: bokc bokc [mailto:youkoun@...]
Sent: Monday, July 07, 2008 9:36 AM
To: user@...
Subject: Re: [mule-user] Attach File to E-mail (SMTP)

 

Hi,

I saw you use a ObjectToEmailMessage transformer. It is possible to get source code or some explication like output object type, parameters of this object,...?

Thanks,

Youkoun

2008/7/7 Wayne Wundram <waynew@...>:

Dear Vinith,

Sorry, these are for version 1.4.3. Here is the excerpt of the config
file that emails the attachment.

               <mule-descriptor name="GGEmailOrders"

implementation="org.mule.components.simple.PassThroughComponent">
                       <inbound-router>
                               <endpoint
address="vm://gargoyle.orders.email" />
                       </inbound-router>
                       <outbound-router>
                               <router

className="org.mule.routing.outbound.OutboundPassThroughRouter">
                                       <endpoint

address="smtp://${smtp.host}?address=${salesorder.toAddress}"

transformers="ObjectToEmailMessage GGMailContentsToAttachment" />
                               </router>
                       </outbound-router>
               </mule-descriptor>

Regards,
Wayne Wundram



-----Original Message-----
From: VinithGowda [mailto:vinith.hr@...]

Sent: Friday, July 04, 2008 8:48 AM
To: user@...

Subject: RE: [mule-user] Attach File to E-mail (SMTP)


To be more clear with you I am using Mule 2.x

Thanks
Vinith Gowda

Wayne Wundram wrote:
>
> I created a Transformer that takes the content of the message and
> attaches it to an email. The code of my transformer is:
>
>
>
> /*
>
>  * To change this template, choose Tools | Templates
>
>  * and open the template in the editor.
>
>  */
>
>
>
> package miraculum.mule;
>
>
>
> import java.io.IOException;
>
> import javax.mail.Message;
>
> import javax.mail.MessagingException;
>
> import javax.mail.Multipart;
>
> import javax.mail.internet.MimeBodyPart;
>
> import javax.mail.internet.MimeMessage;
>
> import javax.mail.internet.MimeMultipart;
>
> import org.apache.log4j.Logger;
>
> import org.mule.transformers.AbstractTransformer;
>
> import org.mule.umo.transformer.TransformerException;
>
> import org.mule.util.DateUtils;
>
>
>
> /**
>
>  *
>
>  * @author Wayne Wundram
>
>  *
>
>  *  Mule Transformer to take the contents of a Mail Message
>
>  *  and send it as an attachment.
>
>  *
>
>  */
>
> public class TfmMailContentsToAttachment extends AbstractTransformer {
>
>     private String attachmentName;
>
>     public static final String DEFAULT_DATE_FORMAT =
> "yyyy-MM-dd_HH-mm-ss.SSS";
>
>
>
>     static Logger log =
> Logger.getLogger(TfmMailContentsToAttachment.class.getName());
>
>
>
>     public TfmMailContentsToAttachment() {
>
>         super();
>
>         this.registerSourceType(Message.class);
>
>         this.setReturnClass(Message.class);
>
>     }
>
>
>
>     public Object doTransform(Object src, String encoding) throws
> TransformerException {
>
>
>
>         MimeMessage inputMessage = (MimeMessage) src;
>
>
>
>         // If the attachmentName property is not set then default it.

>
>         if (getAttachmentName() == null) {
>
>             setAttachmentName("attachment.txt");
>
>         }
>
>         String generatedName = getAttachmentName();
>
>         if (generatedName.indexOf("{DATE}") > -1) {
>
>             String currentDate =
> DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);
>
>             generatedName = generatedName.replace("{DATE}",
> currentDate);
>
>             setAttachmentName(generatedName);
>
>         }
>
>
>
>         // Move content to an attachment.
>
>         try {
>
>             MimeBodyPart mimeBodyPart = new MimeBodyPart();
>
>
>
mimeBodyPart.setContent(inputMessage.getContent(),inputMessage.getConten
> tType());
>
>             mimeBodyPart.setFileName(getAttachmentName());
>
>             Multipart multipart = new MimeMultipart();
>
>             multipart.addBodyPart(mimeBodyPart);
>
>             inputMessage.setContent(multipart);
>
>
>
>         } catch (IOException ioe) {
>
>             log.error("IOException " + ioe.getMessage());
>
>             throw new TransformerException(this, ioe);
>
>         } catch (MessagingException me) {
>
>             log.error("MessagingException " + me.getMessage());
>
>             throw new TransformerException(this, me);
>
>
>
>         }
>
>         return inputMessage;
>
>     }
>
>
>
>     public String getAttachmentName() {
>
>         return attachmentName;
>
>     }
>
>
>
>     public void setAttachmentName(String attachmentName) {
>
>         this.attachmentName = attachmentName;
>
>     }
>
> }
>
>
>
>
>
> I used it in my config file as follows:
>
>
>
>             <transformer name="GGMailContentsToAttachment"
>
>
className="miraculum.mule.TfmMailContentsToAttachment"
>
>                   returnClass="javax.mail.Message">
>
>                   <properties>
>
>                         <property name="attachmentName"
> value="GA01-{DATE}.txt" />
>
>                   </properties>
>
>             </transformer>
>
>
>
> Regards,
>
> Wayne Wundram
>
>
>
> ________________________________
>
> From: VinithGowda [mailto:vinith.hr@...]
> Sent: Friday, July 04, 2008 7:16 AM
> To: user@...
> Subject: [mule-user] Attach File to E-mail (SMTP)
>
>
>
> Hi All, I would like to attach a file to the mail sending through SMTP
> connector,which is the best way doing it. Thanks in Advance, Vinith
> Gowda.
>
> ________________________________
>
> View this message in context: Attach File to E-mail (SMTP)
>
<http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p18272
> 975.html>
> Sent from the Mule - User mailing list archive
> <http://www.nabble.com/Mule---User-f2727.html>  at Nabble.com.
>
>
>

--
View this message in context:
http://www.nabble.com/Attach-File-to-E-mail-%28SMTP%29-tp18272975p182738
51.html

Sent from the Mule - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email

 


Re: Attach File to E-mail (SMTP)

by yantzefr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I found a solution which consists in creating one Transformer upstream to the call to ObjectToMimeMessage.
The role of this Transform it will be to add the attachment document and to put the contents body of the email.

Mule config file :

....
<connector name="EmailConnector" className="org.mule.providers.email.SmtpConnector">
   <properties>
       <property name="host" value="${SMTP_HOST}" />
       <property name="port" value="${SMTP_PORT}" />
       <property name="username" value="${SMTP_USER}" />
       <property name="password" value="${SMTP_PASSWORD}" />
       <property name="subject" value="${SMTP_SUBJECT}"/>
       <property name="fromAddress" value="${SMTP_FROM_ADDRESS}"/>
   </properties>
</connector>

<transformers>
        <transformer name="FileToAttachedFileTransformer" className="com.gb.ram.common.mule.transformer.FileToAttachedFile" />
        <transformer name="ObjectToMimeMessageTransformer" className="org.mule.providers.email.transformers.ObjectToMimeMessage" returnClass="javax.mail.Message" />
....
</transformers>
....

<mule-descriptor name="SendEmailWithAttachmentFile" implementation="com.gb.ram.mule.component.DummyComponent">
....
....

<outbound-router>
    <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
        <endpoint address="smtp://${SMTP_HOST}" connector="EmailConnector" transformers="FileToAttachedFileTransformer ObjectToMimeMessageTransformer">
        <properties>
                        <property name="toAddresses" value="${SMTP_TO_ADDRESS}" />
                        <property name="contentType" value="text/plain" />
                </properties>
      </endpoint>
   </router>
</outbound-router>
</mule-descriptor>
...
...


Code of the "DummyComponent" : it do nothing

public class DummyComponent {
        /**
         * @param contenu
         * @return
         */
        public Object contenu(Object content) {
                System.out.println("*-*-*-*-*-*-*-* DummyComponent : " + content);
            return contenu;
        }

Code of the FileToAttachedFile Transformer :

public class FileToAttachedFile extends AbstractEventAwareTransformer {

        private final String BODY_EMAIL = "Hello,\r\n\r\n\r\nI'm very happy!!";
       
        public Object transform(Object source, String encoding, UMOEventContext context) throws TransformerException {
               
                UMOMessage message = context.getMessage();
               
                try {
                        //attachment file "payload"
                        String pathFile = message.getUniqueId();
                        FileDataSource attachFile = new FileDataSource(pathFile);

                        //attachment external file
                        //FileDataSource attachFile = new FileDataSource("<path_string_file>");


                        message.addAttachment("firstAttachmentFile", new DataHandler(attachFile));
                       
                        return BODY_EMAIL;

                } catch (Exception e) {
                        Message messageErreur = MessageFactory.createStaticMessage("Error FileToAttachedFile");
                        throw new TransformerException(messageErreur, e);
                }
        }

I'm testing this code and it's running fine