Hello Niclas,

thanks for that code.

I have to find out how I can put this in XSP.

I will let the list know whether I had success.

...again thank you very much.
...it already helps to understand more about the multiple attachments.

King Regards
Thorsten

Niclas Hedhman wrote:
Here is my code for making multiple attachments (in Java though, not XSP and don't know if there are any "issues" of XSP involved)

htmlContent contains the HTML text.
xmlContent contains the XML text.
qtxcontent is a text file in proprietary format

connectTransport();
MimeMultipart mmp = new MimeMultipart();
InternetHeaders headers;
MimeBodyPart mbp;
String[] images = getImageNames();

mbp = new MimeBodyPart();
mbp.setContent( description, "text/plain" );
mmp.addBodyPart( mbp );

mbp = new MimeBodyPart();
mbp.setDataHandler(new DataHandler( new ByteArrayDataSource( htmlContent, "text/html")));
mbp.setHeader( "Content-Disposition", "inline;\n\tfilename=\"ewarna.com.html\"" );
mmp.addBodyPart( mbp );

headers = new InternetHeaders();
headers.setHeader( "Content-Type", "application/octet-stream;\n\tname=\"color.qtx\"" );
headers.setHeader( "Content-Transfer-Encoding", "quoted-printable" );
headers.setHeader( "Content-Disposition", "attachment;\n\tfilename=\"color.qtx\"" );

ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream out = MimeUtility.encode( baos, "quoted-printable" );
out.write( qtxcontent.getBytes() );

mbp = new MimeBodyPart( headers, baos.toByteArray() );
mmp.addBodyPart( mbp );

mbp = new MimeBodyPart();
mbp.setDataHandler(new DataHandler( new ByteArrayDataSource( xmlContent, "text/xml")));
mbp.setHeader( "Content-Disposition", "attachment;\n\tfilename=\"ewarna.com.xml\"" );
mmp.addBodyPart( mbp );

MimeMessage msg = new MimeMessage( m_Session );
if( from != null )
{
msg.setFrom( from );
msg.setReplyTo( new Address[] { from } );
m_Logger.debug( "Creating an email from " + msg.getFrom()[0] );
}
else
{
m_Logger.warn( "FROM field was null." );
m_Logger.info( "Creating an email from <null>." );
}
msg.setRecipients( Message.RecipientType.TO, addresses );
msg.setSentDate( sentDate );
msg.setSubject( subject );
msg.setContent( mmp );
m_Logger.info( "Message composed." );
if( m_Transport != null )
m_Transport.sendMessage( msg, addresses );
m_Logger.info( "Message sent." );


private void connectTransport()
throws MessagingException
{
if( ! m_Transport.isConnected() )
{
String host = m_Session.getProperty( "mail.smtp.host" );
if( host == null )
host = m_Session.getProperty( "mail.host" );

String user = m_Session.getProperty( "mail.smtp.user" );
if( user == null )
user = m_Session.getProperty( "mail.user" );

String password = m_Session.getProperty( "mail.smtp.password" );
if( password == null )
password = m_Session.getProperty( "mail.password" );

m_Transport.connect( host, user, password );
}
}



copyright disclaimer; This code is provide as-is, to be used in any way whatsoever, with no explicit nor implicit warranties.

I hope that helps....

Niclas

On Wednesday 29 January 2003 05:49, Thorsten Scherler wrote:

You're right! But most of the time I was posting in regard of that:

http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=103803474424981&w=2
Bernhard Huber answered me:
So you may want to enhance the
src\java\org\apache\cocoon\components\language\markup\xsp\java\sendmail.xsl
for adding attachments, and provide it as patch.
As a hint you may have to study the javamail API for adding an
attachment to the MimeMessage object

So now I think I have to do that:
In Java you have to do the following (according to
http://www.developer.com/java/other/article.php/618471).
...
if(null == fields.get("attachment"))
msg.setText((String)fields.get("body"));
else
{
BodyPart body = new MimeBodyPart(),
attachment =
   (BodyPart)fields.get("attachment");
body.setText((String)fields.get("body"));
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(body);
multipart.addBodyPart(attachment);
msg.setContent(multipart);
...

Geoff Howard wrote:

there were some messages on this a month or so ago.  Have you searched
the archives for it for both the dev and users list?

Geoff Howard


-----Original Message-----
From: Scherler, Thorsten [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 28, 2003 12:04 PM
To: [EMAIL PROTECTED]
Subject: AW: Attachments within sendmail


Thanks for the reply.

i thought nobody but me would like to have that capability.

I am working on it (at the moment without any success).

-----Ursprüngliche Nachricht-----
Von: Pier Fumagalli [mailto:[EMAIL PROTECTED]]
Gesendet: Dienstag, 28. Januar 2003 17:59
An: [EMAIL PROTECTED]
Betreff: Re: Attachments within sendmail


I'd like to have that capability (as I already use it on my employer's
site), but I'll need to get acquainted with that part of the code before
commenting on it... Maybe in a couple of weeks...

  Pier

"Scherler, Thorsten" <[EMAIL PROTECTED]> wrote:

Am I the only one, who wants to attach files to sendmail?


Mit freundlichem Gruss,

Thorsten Scherler
Marketing / Telefonmarketing

Weidmüller GmbH & Co.
P.O. Box 2807
33058 Paderborn
Tel.:+ 49 - 5252-960-350
Fax:+ 49 - 5252-960-116
eMail: [EMAIL PROTECTED]
http://www.weidmueller.de
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to