Hi,
the central stuff follows. Put the appropriate
parameters into a hashtable and call this method.
ron
private void sendMail( Hashtable params ) throws
AddressException, MessagingException
{
String mailServer = (String) params.get(
"mailServer" );
String subject = (String) params.get(
"subject" );
String to[] = (String[]) params.get( "to" );
String cc[] = (String[]) params.get( "cc" );
String from = (String) params.get( "from" );
String messageText = (String) params.get(
"messageText" );
Properties mailProps = new Properties();
mailProps.put( "mail.smtp.host", mailServer
);
Session mailSession =
Session.getDefaultInstance( mailProps, null );
int toCount = to.length;
InternetAddress[] toAddr = new
InternetAddress[ toCount ];
for( int i = 0; i < toCount; i++ )
{
toAddr[ i ] = new InternetAddress( to[ i
].trim() );
}
InternetAddress[] ccAddr = null;
if( null != cc )
{
int ccCount = cc.length;
ccAddr = new InternetAddress[ ccCount ];
for( int i = 0; i < ccCount; i++ )
{
ccAddr[ i ] = new InternetAddress( cc[ i
].trim() );
}
}
InternetAddress fromAddr = new
InternetAddress( from.trim() );
Message message = new MimeMessage(
mailSession );
message.setFrom( fromAddr );
message.setRecipients(
Message.RecipientType.TO, toAddr );
if( null != ccAddr )
message.setRecipients( Message.RecipientType.CC,
ccAddr );
message.setSubject( subject );
//message.setContent( messageText,
"text/html" );
//message.setText( messageText );
MimeMultipart mp = new MimeMultipart();
MimeBodyPart b1 = new MimeBodyPart();
b1.setContent( messageText, "text/html" );
mp.addBodyPart( b1 );
message.setContent( mp );
message.saveChanges();
//message.setDataHandler(new DataHandler(new
ByteArrayDataSource(messageText, "text/html")));
Transport.send( message );
}
--- "Antonio W. Lagnada" <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> Does anyone have a simple example on how send an
> email for in JSP or
> Servlet?
>
> Any help would be appreciated.
> Thanks
>
> --
> Antonio W. Lagnada
> Ecommerce Consultant
> [EMAIL PROTECTED]
>
> This email address is specifically
> for JSP-Interest email list.
> Remove _NOSPAM for the actual email.
>
>
>
>
___________________________________________________________________
> To get your own FREE ZDNet Onebox - FREE voicemail,
> email, and fax,
> all in one place - sign up today at
> http://www.zdnetonebox.com
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
__________________________________________________
Do You Yahoo!?
Yahoo! Calendar - Get organized for the holidays!
http://calendar.yahoo.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets