<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>java-mail &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/java-mail/</link>
	<description>Feed of posts on WordPress.com tagged "java-mail"</description>
	<pubDate>Sat, 18 May 2013 19:22:48 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[JavaMail API: Sending Mail with attachment via Gmail SMTP on SSL]]></title>
<link>http://jyotiranjanpattnaik.wordpress.com/2013/01/05/313/</link>
<pubDate>Sat, 05 Jan 2013 10:04:28 +0000</pubDate>
<dc:creator>jrp</dc:creator>
<guid>http://jyotiranjanpattnaik.wordpress.com/2013/01/05/313/</guid>
<description><![CDATA[Hello Devs, In this article, I am going to write &#8220;how to send email with or w/o attachment via]]></description>
<content:encoded><![CDATA[<div style="font-size:16px;">Hello Devs,</p>
<p>In this article, I am going to write &#8220;how to send email with or w/o attachment via Gmail SMTP on SSL(Secure Socket Layer)&#8221;.<br />
For Gmail SMTP, see this <a title="GMAIL SMTP" href="http://support.google.com/mail/bin/answer.py?hl=en&#38;answer=13287" target="_blank">link</a><br />
To run the below code, you need 2 jars.</p>
<ol>
<li>activation.jar &#8211; Get it from <a title="activation" href="http://www.java2s.com/Code/Jar/a/Downloadactivationjar.htm" target="_blank">here<br />
</a></li>
<li>mail.jar &#8211; Get it from <a title="mail.jar" href="http://www.java2s.com/Code/Jar/m/Downloadmailjar.htm" target="_blank">here</a></li>
</ol>
<p>Here is the code&#8230;
</p></div>
<pre><code>
import java.io.File;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class MailerTest {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("SenderEmailId","Password");
            }
        });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("SenderEmailId"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("RecipientEmailId"));
            message.setSubject("Sample Mail with Attachment");
            BodyPart messageBodyPart = new MimeBodyPart();
            Multipart multipart = new MimeMultipart();
            File file = new File("file name with path");
            DataSource source = new FileDataSource(file);
            messageBodyPart.setDataHandler(new DataHandler(source));
            String filename = "filename";
            messageBodyPart.setFileName(filename);
            multipart.addBodyPart(messageBodyPart);
            BodyPart messageBodyPart2 = new MimeBodyPart();
            messageBodyPart2.setText("Hello User"+"\n\n"+"Enjoy Mail service from a Java App"+
                    "\n\n"+ "NB: Please don't reply to this mail. It is a system generated message.");
            multipart.addBodyPart(messageBodyPart2);
            message.setContent(multipart);

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

</code></pre>
<p>*For complete reference of different kind of mail, you can see this <a title="Mail Reference" href="http://www.vipan.com/htdocs/javamail.html" target="_blank">link</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Emails in Groovy, Part 1: SMTP]]></title>
<link>http://mtaylorprogramming.wordpress.com/2012/12/30/emails-in-groovy-part-1-smtp/</link>
<pubDate>Sun, 30 Dec 2012 17:03:12 +0000</pubDate>
<dc:creator>mtaylorprogramming</dc:creator>
<guid>http://mtaylorprogramming.wordpress.com/2012/12/30/emails-in-groovy-part-1-smtp/</guid>
<description><![CDATA[As a continuation of what I discussed in my last post about SMTP in Python, I&#8217;m going to be ta]]></description>
<content:encoded><![CDATA[<p>As a continuation of what I discussed in my last post about SMTP in Python, I&#8217;m going to be talking about SMTP in Groovy. To get started you need the Java Mail Library, available from Oracle&#8217;s website. If you don&#8217;t know Groovy you should be able to read and understand this, assuming you know Java.</p>
<p>I wrote this program in about a half hour, but I already had some basic knowledge of the Java Mail API. I made an Email Account object, figuring that would be the most efficient way of building this program.</p>
<pre class="brush: groovy; title: ; notranslate" title="">import javax.mail.*
import javax.mail.internet.*

class GroovyEmailer {

    private String username, password, host = &#34;smtp.gmail.com&#34;

    GroovyEmailer() {
        username = &#34;&#34;
        password = &#34;&#34;
    }
    GroovyEmailer(String usename, String passcode) {
        username = usename
        password = passcode
    }
    void sendMail(String to, String subject, String message){
        def props = new Properties()
        propsput &#34;mail.smtps.auth&#34;, &#34;true&#34;

        def session = SessiongetDefaultInstance props, null

        def msg = new MimeMessage(session)

        msg setSubject subject
        msg setText message
        msg addRecipient Message RecipientType.To, new InternetAddress(to, to)

        def transport = session getTransport &#34;smtps&#34;

        try {
            transport connect (host, username, password)
            transport sendMessage (msg, msg.getAllRecipients())
       }
        catch (Exception e) {
            println &#34;Error&#34;
       }
    }
}
</pre>
<p>The next class is just a runner:</p>
<pre class="brush: groovy; title: ; notranslate" title="">class EmailRunner {

    static void main(String[] args) {

        def myScanner = new Scanner(System.in)

        print &#34;Enter your gmail username :: &#34;
        String email = myScanner nextLine()

        print &#34;\nEnter your gmail password :: &#34;
        String password = myScanner nextLine()

        print &#34;\nEnter the address to send to :: &#34;
        String to = myScanner nextLine()

        print &#34;\nEnter the message subject :: &#34;
        String subject = myScanner nextLine()

        print &#34;\nEnter the message :: &#34;
        String message = myScanner nextLine()

        def emailer = new GroovyEmailer(email, password)

        emailer.sendMail to, subject, message
    }
}
</pre>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Sending Mail using Java Mail API]]></title>
<link>http://pugazenthy.wordpress.com/2012/07/24/sending-mail-using-java-mail-api-2/</link>
<pubDate>Tue, 24 Jul 2012 09:32:15 +0000</pubDate>
<dc:creator>Pugaz</dc:creator>
<guid>http://pugazenthy.wordpress.com/2012/07/24/sending-mail-using-java-mail-api-2/</guid>
<description><![CDATA[import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import]]></description>
<content:encoded><![CDATA[import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import]]></content:encoded>
</item>
<item>
<title><![CDATA[Sending mail programmatically using JAVA mail API]]></title>
<link>http://nishitshah85.wordpress.com/2012/06/04/sending-mail-programatically-using-java-mail-api/</link>
<pubDate>Mon, 04 Jun 2012 03:59:16 +0000</pubDate>
<dc:creator>nishitshah85</dc:creator>
<guid>http://nishitshah85.wordpress.com/2012/06/04/sending-mail-programatically-using-java-mail-api/</guid>
<description><![CDATA[Hi All, Here is the way, using following class  and its APIs one can send mail programmatically to e]]></description>
<content:encoded><![CDATA[<p>Hi All,</p>
<p>Here is the way, using following class  and its APIs one can send mail programmatically to end users.Here you go:</p>
<p>JAVA provides APIs if you wish to send mail through code. One can also utilize it to send excel sheet of selenium test case results via mail after the end of automation script execution.</p>
<p>you can download JAVA mail API from following URL:</p>
<p><a href="http://www.oracle.com/technetwork/java/javamail/index.html" rel="nofollow">http://www.oracle.com/technetwork/java/javamail/index.html</a></p>
<p>Steps:</p>
<p>Download the mail api jar from given site.</p>
<p>Create a project in Eclipse/Netbeans ide.</p>
<p>Add this jar into project.</p>
<p>create a class and copy the code snippet given below to your class.</p>
<p>use its methods into your custom class where you want to utilize it.</p>
<p>Here is the code sample:</p>
<p>package com.Testscript;</p>
<p>import java.util.Properties;</p>
<p>import javax.activation.DataHandler;</p>
<p>import javax.activation.DataSource;</p>
<p>import javax.activation.FileDataSource;</p>
<p>import javax.mail.Authenticator;</p>
<p>import javax.mail.BodyPart;</p>
<p>import javax.mail.Message;</p>
<p>import javax.mail.MessagingException;</p>
<p>import javax.mail.Multipart;</p>
<p>import javax.mail.PasswordAuthentication;</p>
<p>import javax.mail.Session;</p>
<p>import javax.mail.Transport;</p>
<p>import javax.mail.internet.AddressException;</p>
<p>import javax.mail.internet.InternetAddress;</p>
<p>import javax.mail.internet.MimeBodyPart;</p>
<p>import javax.mail.internet.MimeMessage;</p>
<p>import javax.mail.internet.MimeMultipart;</p>
<p>public class Mailsetup</p>
<p>{</p>
<p><strong>//First Approach without authentication</strong></p>
<p>Properties props = new Properties();</p>
<p>Authenticator auth;</p>
<p>// fill props with any information</p>
<p>Session session = Session.getInstance(props, null);</p>
<p>public void sendmail() throws MessagingException,AddressException</p>
<p>{</p>
<p>props = session.getProperties();</p>
<p>InternetAddress address = new InternetAddress(&#8220;<em>sender&#8217;s mail address</em>&#8220;);</p>
<p>InternetAddress RecipientAddress=new InternetAddress(&#8220;<em>recipient&#8217;s address</em>&#8220;);</p>
<p>MimeMessage message = new MimeMessage(session);</p>
<p>message.setContent(&#8220;Hello&#8221;, &#8220;text/plain&#8221;);</p>
<p>message.setSubject(&#8220;First&#8221;);</p>
<p>message.setFrom(address);</p>
<p>message.addRecipient(RecipientType.TO, RecipientAddress);</p>
<p>Transport.send(message);</p>
<p>}</p>
<p>public void main(String[] args)</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>sendmail();</p>
<p>}</p>
<p>catch (Exception e) {</p>
<p>// TODO: handle exception</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>The above mentioned approach is not recommended since mail sent without authentication may go into spam and end user will not come to know about it unless and until he/she checks her junk mailbox. Therefore use below mentioned approach to make sure that end user gets mail in his/her inbox.</p>
<p><strong> //This is another approach with authentication</strong></p>
<p>public void sendMail(String mailServer, String from, String[] to,String subject, String messageBody,String[] attachments) throws MessagingException, AddressException</p>
<p>{</p>
<p>/*</p>
<p>PasswordAuthentication authentication;</p>
<p>authentication = new PasswordAuthentication(&#8220;<em>sender&#8217;s email address</em>&#8220;, &#8220;<em>sender&#8217;s password</em>&#8220;);</p>
<p>*/</p>
<p>// Setup mail server</p>
<p>Properties props = System.getProperties();</p>
<p>// Setup mail server</p>
<p>props.put(&#8220;mail.smtp.host&#8221;, mailServer);</p>
<p>props.put(&#8220;mail.smtp.port&#8221;,<em> port number</em>);</p>
<p>props.put(&#8220;mail.transport.protocol&#8221;, &#8220;smtp&#8221;);</p>
<p>props.put(&#8220;mail.smtp.starttls.enable&#8221;, &#8220;true&#8221;);</p>
<p>props.put(&#8220;mail.smtp.auth&#8221;, &#8220;true&#8221;);</p>
<p>Authenticator auth = new MailAuthenticator();</p>
<p>// Get a mail session</p>
<p>//Session session = Session.getDefaultInstance(props,new MailAuthenticator());</p>
<p>Session session = Session.getDefaultInstance(props,auth);</p>
<p>// Define a new mail message</p>
<p>Message message = new MimeMessage(session);</p>
<p>message.setFrom(new InternetAddress(from));</p>
<p>message.setSubject(subject);</p>
<p>// Create a message part to represent the body text</p>
<p>BodyPart messageBodyPart = new MimeBodyPart();</p>
<p>messageBodyPart.setText(messageBody);</p>
<p>//use a MimeMultipart as we need to handle the file attachments</p>
<p>Multipart multipart = new MimeMultipart();</p>
<p>//add the message body to the mime message</p>
<p>multipart.addBodyPart(messageBodyPart);</p>
<p>// add any file attachments to the message</p>
<p>addAtachments(attachments, multipart);</p>
<p>// Put all message parts in the message</p>
<p>message.setContent(multipart);</p>
<p>// Send the message</p>
<p>for(int i=0;i&#60;=to.length-1;i++)</p>
<p>{</p>
<p>message.setRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));</p>
<p>Transport.send(message);</p>
<p>}</p>
<p>System.out.println(&#8220;Mail Sent&#8221;);</p>
<p>}</p>
<p>protected void addAtachments(String[] attachments, Multipart multipart)</p>
<p>throws MessagingException, AddressException</p>
<p>{</p>
<p>for(int i = 0; i&#60;= attachments.length -1; i++)</p>
<p>{</p>
<p>String filename = attachments[i];</p>
<p>MimeBodyPart attachmentBodyPart = new MimeBodyPart();</p>
<p>//use a JAF FileDataSource as it does MIME type detection</p>
<p>DataSource source = new FileDataSource(filename);</p>
<p>attachmentBodyPart.setDataHandler(new DataHandler(source));</p>
<p>//assume that the filename you want to send is the same as the</p>
<p>//actual file name &#8211; could alter this to remove the file path</p>
<p>attachmentBodyPart.setFileName(filename);</p>
<p>//add the attachment</p>
<p>multipart.addBodyPart(attachmentBodyPart);</p>
<p>}</p>
<p>}</p>
<p>public static void main(String[] args)</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>Mailsetup client = new Mailsetup();</p>
<p>String server=&#8221;<em>mail server host address</em>&#8220;;</p>
<p>String[] to={&#8220;<em>recipient&#8217;s email address</em>&#8220;};//one can add more than one address here to send mail to multiple recipients.</p>
<p>String from = &#8220;<em>sender&#8217;s email address</em>&#8220;;</p>
<p>String subject=&#8221;Automation Test Result&#8221;;</p>
<p>String message=&#8221;Hi This is for testing.&#8221;;</p>
<p>String[] filenames ={&#8220;<em>attachment filepath</em>&#8220;};</p>
<p>client.sendMail(server,from,to,subject,message,filenames);</p>
<p>}</p>
<p>catch(Exception e)</p>
<p>{</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>class MailAuthenticator extends Authenticator {</p>
<p>public MailAuthenticator() {</p>
<p>}</p>
<p>public PasswordAuthentication getPasswordAuthentication() {</p>
<p>return new PasswordAuthentication(&#8220;<em>email address</em>&#8220;, &#8220;<em>password</em>&#8220;);</p>
<p>}</p>
<p>}</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Mail - Gmail SMTP server]]></title>
<link>http://mlusincuba.wordpress.com/2012/03/03/java-mail-gmail-smtp-client/</link>
<pubDate>Sat, 03 Mar 2012 01:23:06 +0000</pubDate>
<dc:creator>mlusincuba</dc:creator>
<guid>http://mlusincuba.wordpress.com/2012/03/03/java-mail-gmail-smtp-client/</guid>
<description><![CDATA[This code works as long as you have internet connection and gmail account. Use you gmail address and]]></description>
<content:encoded><![CDATA[<p>This code works as long as you have internet connection and gmail account. Use you gmail address and password where required and test it for your self.</p>
<p>Listing 1 &#8211; Maven dependency</p>
<pre class="brush: xml; title: ; notranslate" title="">
&#60;repositories&#62;
        &#60;repository&#62;
            &#60;id&#62;Java.Net&#60;/id&#62;
            &#60;url&#62;http://download.java.net/maven/2/&#60;/url&#62;
        &#60;/repository&#62;
    &#60;/repositories&#62;
  
    &#60;dependencies&#62;
        &#60;dependency&#62;
	 &#60;groupId&#62;javax.mail&#60;/groupId&#62;
	 &#60;artifactId&#62;mail&#60;/artifactId&#62;
	 &#60;version&#62;1.4.3&#60;/version&#62;
        &#60;/dependency&#62; 
    &#60;/dependencies&#62;
</pre>
<p>Listing 2 &#8211; GMail.java</p>
<pre class="brush: java; title: ; notranslate" title="">
package com.mycompany.employee.utils;

import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * @author Mlungisi
 *
 */
public class GMail {

    public static void sendMail(String senderEmail, String recipientEmail, String subject, String message) throws MessagingException, UnsupportedEncodingException {
        // TLS
        Properties propsTLS = new Properties();
        propsTLS.put(&#34;mail.transport.protocol&#34;, &#34;smtp&#34;);
        propsTLS.put(&#34;mail.smtp.host&#34;, &#34;smtp.gmail.com&#34;);
        propsTLS.put(&#34;mail.smtp.auth&#34;, &#34;true&#34;);
        propsTLS.put(&#34;mail.smtp.starttls.enable&#34;, &#34;true&#34;); // GMail requires STARTTLS

        Session sessionTLS = Session.getInstance(propsTLS);
        sessionTLS.setDebug(true);

        Message messageTLS = new MimeMessage(sessionTLS);
        messageTLS.setFrom(new InternetAddress(&#34;yourgmail@gmail.com&#34;, &#34;Mlungisi Sincuba&#34;));
        messageTLS.setRecipients(Message.RecipientType.TO, InternetAddress.parse(&#34;yourgmail@gmail.com&#34;)); // real recipient
        messageTLS.setSubject(&#34;Test mail using TLS&#34;);
        messageTLS.setText(&#34;This is test email sent to Your account using TLS.&#34;);

        Transport transportTLS = sessionTLS.getTransport();
        transportTLS.connect(&#34;smtp.gmail.com&#34;, 587, &#34;yourgmail@gmail.com&#34;, &#34;yourpassword&#34;); // account used
        transportTLS.sendMessage(messageTLS, messageTLS.getAllRecipients());
        transportTLS.close();

        System.out.println(&#34;TLS done.&#34;);
        System.out.println(&#34;------------------------------------------------------------------------&#34;);

        // SSL			
        Properties propsSSL = new Properties();
        propsSSL.put(&#34;mail.transport.protocol&#34;, &#34;smtps&#34;);
        propsSSL.put(&#34;mail.smtps.host&#34;, &#34;smtp.gmail.com&#34;);
        propsSSL.put(&#34;mail.smtps.auth&#34;, &#34;true&#34;);

        Session sessionSSL = Session.getInstance(propsSSL);
        sessionSSL.setDebug(true);

        Message messageSSL = new MimeMessage(sessionSSL);
        messageSSL.setFrom(new InternetAddress(&#34;yourgmail@gmail.com&#34;, &#34;Mlungisi Sincuba&#34;));
        messageSSL.setRecipients(Message.RecipientType.TO, InternetAddress.parse(&#34;yourgmail@gmail.com&#34;)); // real recipient
        messageSSL.setSubject(&#34;Test mail using SSL&#34;);
        messageSSL.setText(&#34;This is test email sent to Your account using SSL.&#34;);

        Transport transportSSL = sessionSSL.getTransport();
        transportSSL.connect(&#34;smtp.gmail.com&#34;, 465, &#34;yourgmail@gmail.com&#34;, &#34;yourpassword&#34;); // account used
        transportSSL.sendMessage(messageSSL, messageSSL.getAllRecipients());
        transportSSL.close();

        System.out.println(&#34;SSL done.&#34;);
        System.out.println(&#34;------------------------------------------------------------------------&#34;);

    }

    public static void main(String[] args) throws MessagingException, UnsupportedEncodingException {
        System.out.println(&#34;Hello World!&#34;);
        sendMail(null, null, null, null);
    }
}

</pre>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Sending Mail using Java Mail API]]></title>
<link>http://pugazenthy.wordpress.com/2012/01/05/sending-mail-using-java-mail-api/</link>
<pubDate>Thu, 05 Jan 2012 19:13:48 +0000</pubDate>
<dc:creator>Pugaz</dc:creator>
<guid>http://pugazenthy.wordpress.com/2012/01/05/sending-mail-using-java-mail-api/</guid>
<description><![CDATA[import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import]]></description>
<content:encoded><![CDATA[import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import]]></content:encoded>
</item>
<item>
<title><![CDATA[Sending emails via command line]]></title>
<link>http://oraclemiddlewareblog.com/2012/01/05/sending-emails-via-command-line/</link>
<pubDate>Thu, 05 Jan 2012 14:00:04 +0000</pubDate>
<dc:creator>radudobrinescu</dc:creator>
<guid>http://oraclemiddlewareblog.com/2012/01/05/sending-emails-via-command-line/</guid>
<description><![CDATA[If you are trying to set up email notification in Weblogic and your emails are not getting through t]]></description>
<content:encoded><![CDATA[<p>If you are trying to set up email notification in Weblogic and your emails are not getting through to your inbox, it might be nothing wrong with your application server configurations, but rather a problem with the email server itself. To test if a regular mail is being sent without having to configure a mail client with that server, you can use the steps below to send an email via command line:<!--more--></p>
<blockquote>
<p style="font-family:Courier New;font-size:10pt;">telnet &#60;email_server_hostname&#62; 25<br />
<em>S: 220 smtp.example.com ESMTP Postfix</em><br />
C: HELO something.com<br />
<em>S: 250 Hello relay.example.org, I am glad to meet you</em><br />
C: MAIL FROM: someone@something.com<br />
<em>S: 250 Ok</em><br />
C: RCPT TO:radu@gmail.com<br />
<em>S: 250 Ok</em><br />
C: RCPT TO:someoneyoumightwanttocc@gmail.com<br />
<em>S: 250 Ok</em><br />
C: DATA<br />
<em>S: 354 End data with &#8220;.&#8221;</em><br />
C: From: &#8220;Bob Example&#8221; &#60;bob@example.org&#62;<br />
C: To: &#8220;Alice Example&#8221; &#60;alice@example.com&#62;<br />
C: Cc: theboss@something.com<br />
C: Date: Tue, 15 Jan 2008 16:02:43 -0500<br />
C: Subject: Test message<br />
C:<br />
C: Hello Radu,<br />
C: This is a test message with 5 header fields and 4 lines in the message body.<br />
C: Your friend,<br />
C: Someone<br />
C: .<br />
<em>S: 250 Ok: queued as 12345</em><br />
C: QUIT<br />
<em>S: 221 Bye</em><br />
{The server closes the connection}</p>
</blockquote>
<p><span style="font-family:Courier New;font-size:10pt;">Enjoy!</span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Setting up Watches and Notifications in Weblogic Server]]></title>
<link>http://oraclemiddlewareblog.com/2011/11/14/setting-up-watches-and-notifications-in-weblogic-server/</link>
<pubDate>Mon, 14 Nov 2011 21:47:02 +0000</pubDate>
<dc:creator>radudobrinescu</dc:creator>
<guid>http://oraclemiddlewareblog.com/2011/11/14/setting-up-watches-and-notifications-in-weblogic-server/</guid>
<description><![CDATA[As any IT system administrator knows, it’s crucial to get informed in time of events and certain met]]></description>
<content:encoded><![CDATA[<p>As any IT system administrator knows, it’s crucial to get informed in time of events and certain metrics levels occurring in the systems that you are responsible for. It’s the same with any Fusion Middleware platform, and this kind of functionality is covered by both the Enterprise Manager Grid Control, but also by the Weblogic Server itself. So if you are only using the Weblogic Administration console for monitoring your Weblogic platform, you can still set up alerts to inform you on the state of your system. This post will cover just such a setup that will send email notifications to the administrators, although SNMP traps, JMX, and JMS are also supported.</p>
<p>To set up your email alerts you will need to cover these main steps:<!--more--></p>
<ol>
<li>In our specific case of email notifications, you need to set up a JavaMailSession object, that will actually be used by the Notifications to send the alerts through the specified email server;</li>
<li>Set up a diagnostic module and define any metrics that you would like to collect;</li>
<li>Define the Watches you are interested in &#8211; this is the situation that you want to trigger your alert. It can be a certain message in the log files, or a certain value of a collected metric, or a certain event occurring in the system.</li>
<li>Define the Notifications you would like to receive and associate the Watch to a Notification;</li>
</ol>
<p>In the below example, we will set up alerts on the state of the Weblogic Managed Server, so the admin will get a notification when a server is not in the RUNNING state.</p>
<h4>1.       Set up the Mail Session object.</h4>
<p>Note that the JavaMailSession itself does not offer email server capabilities, but it only provides the JavaMail API so that applications can send and receive email from an already existing server.</p>
<p style="padding-left:30px;">a)      Click &#8220;Lock &#38; Edit&#8221; to acquire a configuration lock</p>
<p style="padding-left:30px;">b)      Expand Services -&#62; Mail Sessions and click &#8220;New&#8221; to create a new Java Mail Session object</p>
<p style="padding-left:30px;">c)       Provide Name, JNDI Name and JavaMail Properties as follow:</p>
<p style="padding-left:30px;"><strong>Name</strong> – WLSAlertsMailSession</p>
<p style="padding-left:30px;"><strong>JNDI Name</strong> &#8211; WLSAlertsMailSession</p>
<p style="padding-left:30px;">(You may enter whatever value here, but it’s best to keep the same value for the two names)</p>
<p style="padding-left:30px;"><strong>JavaMail Properties</strong>:</p>
<p style="padding-left:30px;">mail.debug=&#8221;true&#8221; – not mandatory, but recommended should you want to troubleshoot why your alerts are not getting through</p>
<p style="padding-left:30px;">mail.smtp.port=25</p>
<p style="padding-left:30px;">mail.smtp.from=&#8221;soa_admin@example.com&#8221;</p>
<p style="padding-left:30px;">mail.smtp.host=email.server.example.com</p>
<p style="padding-left:30px;">d)      Click next to target the mail session to a server (either managed or AdminServer) and click finish. You need to do this so that the MailSession is exposed on the servers JNDI tree.</p>
<p style="padding-left:30px;">e)      Activate the changes by clicking &#8220;Activate Changes&#8221;.</p>
<p style="padding-left:30px;"><a href="http://oraclemiddleware.files.wordpress.com/2011/11/javamailsession.jpg"><img class="alignleft size-full wp-image-120" title="JavaMailSession" src="http://oraclemiddleware.files.wordpress.com/2011/11/javamailsession.jpg?w=600&#038;h=383" alt="" width="600" height="383" /></a></p>
<p>You can actually test that your JavaMail properties are correct and that you can send email messages via the email server specified by following the steps described in this post: &#60;link&#62;</p>
<h4>2.       Set up a Diagnostic Module and define a metric of interest as a Collected Metric.</h4>
<p style="padding-left:30px;">a)      Expand Diagnostics -&#62; Diagnostics Modules and click &#8220;New&#8221; to create a new diagnostics module. Provide a name and description.</p>
<p style="padding-left:30px;">Name &#8211; DiagModuleWLDF</p>
<p style="padding-left:30px;">Description &#8211; This is a WLDF module for testing email notifications</p>
<p style="padding-left:30px;">b)      Select the newly created module and select “Targets” tab. Select the appropriate server for target as before</p>
<p style="padding-left:30px;">c)       Click &#8220;Save&#8221; and &#8220;Activate&#8221;</p>
<p style="padding-left:30px;">d)      Click &#8220;Lock &#38; Edit&#8221; to acquire a new configuration lock</p>
<p style="padding-left:30px;">e)      Click on the “Collected Metrics” tab and click “New”</p>
<p style="padding-left:30px;">f)       Select “ServerRuntime” and click “Next”</p>
<p style="padding-left:30px;">g)      Select “ServerRuntimeMBean” from the dropdown</p>
<p style="padding-left:30px;">h)      From the list of collected attributes select “State” and move it in the “Chosen” category; Click “Next”</p>
<p style="padding-left:30px;">i)        From the instances list select the servers you would like to be informed about by selecting an instances and moving it to the “Chosen” category</p>
<p style="padding-left:30px;">j)        Click “Finish”</p>
<p style="padding-left:30px;">k)      Click “Save” and “Activate”</p>
<p>Notice that this metric is collected at a configurable interval, by default 300000ms</p>
<h4>3.       Set up a new Watch rule</h4>
<p style="padding-left:30px;">a)      Click &#8220;Lock &#38; Edit&#8221; to acquire a configuration lock</p>
<p style="padding-left:30px;">b)      Navigate to the diagnostic module created above (DiagModuleWLDF) and select the &#8220;Watches and Notifications&#8221; tab and &#8220;Watches&#8221; sub-tab (if not already selected)</p>
<p style="padding-left:30px;">c)       Click &#8220;New&#8221; to create a new Watch. Provide the name and select the type as &#8220;Collected Metrics&#8221;. Also make sure the watch is enabled.</p>
<p style="padding-left:30px;">Name – ServerStateWatch</p>
<p style="padding-left:30px;">d)      Click &#8220;Next&#8221;</p>
<p style="padding-left:30px;">e)      Click &#8220;Add Expressions&#8221;</p>
<p style="padding-left:30px;">f)       Ensure that &#8220;ServerRuntime&#8221; is selected and click &#8220;Next&#8221;</p>
<p style="padding-left:30px;">g)      From the dropdown, select “ServerRuntimeMBean” again. The click “Next”</p>
<p style="padding-left:30px;">h)      Select the instance for the appropriate server from the list for &#8220;Instance&#8221; and click &#8220;Next&#8221;</p>
<p style="padding-left:30px;">i)        For &#8220;Message Attribute&#8221; select &#8220;State&#8221;, &#8220;!=&#8221; for &#8220;Operator&#8221; and type &#8220;RUNNING&#8221; (all capital letters) for &#8220;Value&#8221;. Click &#8220;Finish&#8221; the Watch</p>
<p style="padding-left:30px;">j)        Activate the changes</p>
<p>This Watch will now be triggered every time the server state is other than RUNNING. Please note that this is dependent on the Collected Metric’s sampling period as well.</p>
<p><img class="alignleft size-full wp-image-130" title="New Picture" src="http://oraclemiddleware.files.wordpress.com/2011/11/new-picture.jpg?w=600&#038;h=153" alt="" width="600" height="153" /></p>
<h4></h4>
<h4></h4>
<h4></h4>
<h4></h4>
<h4>4.       Setting up the Notification and associating it with a certain Watch</h4>
<p style="padding-left:30px;">a)      Click &#8220;Lock &#38; Edit&#8221; to acquire a configuration lock</p>
<p style="padding-left:30px;">b)      Navigate to the diagnostic module created above and select the &#8220;Watches and Notifications&#8221; tab and &#8220;Notification&#8221; sub-tab</p>
<p style="padding-left:30px;">c)       Click &#8220;New&#8221; to create a new Notification</p>
<p style="padding-left:30px;">d)      Select &#8220;SMTP (E-Mail) for Type and click &#8220;Next&#8221;</p>
<p style="padding-left:30px;">e)      Provide a name &#8211; ServerStateNotification. The notification must be enabled, of course. Click “Next”.</p>
<p style="padding-left:30px;">f)       Configure the following properties for the &#8220;Config Notification &#8211; SMTP Properties&#8221; page</p>
<p style="padding-left:30px;">g)      Mail Session Name &#8211; WLSAlertsMailSession</p>
<p style="padding-left:30px;">h)      E-Mail Recipients &#8211; admin@example.com</p>
<p style="padding-left:30px;">i)        Click &#8220;Finish&#8221;.</p>
<p style="padding-left:30px;">j)        Activate the changes</p>
<p>To associate the watch and the notification:</p>
<p style="padding-left:30px;">a)      Click &#8220;Lock &#38; Edit&#8221; to acquire a configuration lock</p>
<p style="padding-left:30px;">b)      Navigate to the diagnostic module created above (DiagModuleWLDF) and select the &#8220;Watches and Notifications&#8221; tab and &#8220;Watches&#8221; sub-tab (if not already selected)</p>
<p style="padding-left:30px;">c)       Select the watch you created earlier &#8211; ServerStateWatch</p>
<p style="padding-left:30px;">d)      Select the &#8220;Notifications&#8221; tab and move the &#8220;ServerStateNotification&#8221; from Available to Chosen</p>
<p style="padding-left:30px;">e)      Click &#8220;Save&#8221;</p>
<p style="padding-left:30px;">f)       Select the &#8220;Alarms&#8221; tab and select &#8220;Use an automatic reset alarm&#8221;. Set the &#8220;Automatic reset period&#8221; so that you don’t get spammed with alerts email  and click &#8220;Save&#8221;.</p>
<p style="padding-left:30px;">g)      Click &#8220;Activate Changes</p>
<p>And that’s it. Next time one of your servers is in a state other than RUNNING (and is picked up by the collected metric based on the sampled period), you will receive an email in the form of:</p>
<p><a href="http://oraclemiddleware.files.wordpress.com/2011/11/mailmessage.jpg"><img class="alignleft size-full wp-image-123" title="MailMessage" src="http://oraclemiddleware.files.wordpress.com/2011/11/mailmessage.jpg?w=600&#038;h=199" alt="" width="600" height="199" /><br />
</a></p>
<p>Of course, both the Subject and the Body of the mail can be customized in the Administration console, in the notification section.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[How to manage Apache Tomcat Scopes with kikonf]]></title>
<link>http://gijeek.wordpress.com/2011/11/07/how-to-manage-apache-tomcat-scopes-with-kikonf/</link>
<pubDate>Mon, 07 Nov 2011 00:44:14 +0000</pubDate>
<dc:creator>Neil Rekoswkajab</dc:creator>
<guid>http://gijeek.wordpress.com/2011/11/07/how-to-manage-apache-tomcat-scopes-with-kikonf/</guid>
<description><![CDATA[This tutorial focuses on the Kikonf plugins for Tomcat. Kikonf provides a set of configuration plugi]]></description>
<content:encoded><![CDATA[<p><span style="font-size:120%;">This tutorial focuses on the Kikonf plugins for <strong>Tomcat</strong>.</span></p>
<p>Kikonf provides a set of configuration plugins for Tomcat, the following is a non explicit list:</p>
<p><strong>tom.alog</strong> : Configure Access log Valves.<br />
<strong>tom.datasrc</strong> : Configure DataSources.<br />
<strong>tom.realm </strong>: Configure Realmes.<br />
<strong>tom.env</strong> : Configure environment entries.<br />
<strong>tom.trans</strong> : Configure Transactions.<br />
<strong>tom.udbrsc</strong> : Configure UDB Databases.<br />
<strong>tom.mailrsc</strong> : Configure Java ® Mail resources.<br />
<strong>tom.beansc</strong> : Configure Java Bean resources.<br />
<strong>tom.crtserver</strong> : Creates new Catalina Bases.<br />
<strong>tom.crtcluster</strong> : Configure Clusters.<br />
<strong>tom.httpconn</strong> : Configure HTTP Connections.<br />
<strong>tom.ajpconn</strong> : Configure AJP Connections.<br />
<strong>tom.aprconn</strong> : Configure APR Connections.<br />
<strong>tom.context</strong> : Configure Contexts.</p>
<p>As explained on the Tomcat official WebSite at:<br />
<a title="Apache Tomcat" href="http://tomcat.apache.org/tomcat-5.5-doc/config/context.html">http://tomcat.apache.org/tomcat-5.5-doc/config/context.html</a><br />
Tomcat configurations can be handle at many scopes.</p>
<p>For example a dataSource may be configured at the Context level into :</p>
<p>- The &#60;CATALINA_BASE&#62;/conf/server.xml file.<br />
- The default &#60;CATALINA_BASE&#62;/conf/context.xml file.<br />
- A default context file for a guiven engine/host at :<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/context.xml.default.xml.<br />
- A root context file at &#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#38;l;tHOSTNAME&#62;ROOT.xml<br />
- A named context file at &#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/&#60;CONTEXT_NAME&#62;.xml</p>
<p>Another example is the Access log Valves that supports the same scopes than before, but can also be configured at the Engine and Host levels.</p>
<p>This tutorial shows you, how to target those many scopes using the special<br />
Kikonf configuration feature: the tag: scope provided for every Kikonf Action.</p>
<p>The following tutorial relays on the Kikonf official documentation for the<br />
scope tag and illustrates, as possible, using tom.alog.</p>
<p>&#8230;<!--more--></p>
<p>A Scope always ends to a specific node into a Tomcat configuration file.<br />
The following list all the scope supported by Kikonf.</p>
<p><strong>a) cbase: &#60;CATALINA_BASE&#62;</strong></p>
<p><em>The value for cbase is an absolute path to a CATALINA_BASE directory.<br />
If not provided cbase takes it default from the software_tom_catalina_base property of the kikonf.attrs file.<br />
If the software_tom_catalina_base property of the kikonf.attrs file is not provided, cbase takes its value from the software_tom_catalina_home.</em></p>
<p>You can set &#8220;cbase&#8221; for a custom directory that you have setup to serve a as Catalina Base.<br />
e.g.:<br />
&#60;scope cbase=&#8217;/webapp/invoices&#8217;/&#62;<br />
All the kikonf Actions for Tomcat configurations will go to this directory.</p>
<p><strong>b) service: &#60;SERVIVE_NAME&#62;</strong></p>
<p><em>Rarely used, but this property allows to switch to another Service node of the &#60;CATALINA_BASE&#62;/conf/server.xml file, when more than one Service node are declared into server.xml.<br />
If not provided the only existing Service node entry within server.xml is used for sub dependant scopes.<br />
To force the default for this Scope alone force the service value to &#8220;*default&#8221;</em>.</p>
<p>If you have many service entries into your server.xml file, you can target a specific one by using this Attribute:<br />
e.g.:<br />
&#60;scope service=&#8217;my_service&#8217;/&#62;</p>
<p><strong>c) engine: &#60;ENGINE_NAME&#62;</strong></p>
<p><em> Rarely used, but this property allows to switch to another Engine node of the &#60;CATALINA_BASE&#62;/conf/server.xml, when more than one Engine node are declared into server.xml.<br />
If not provided the only existing Server node entry within server.xml is used for sub dependant scopes.<br />
To force the default for this Scope alone force the engine value to &#8220;*default&#8221;.</em></p>
<p>If you have many engine entries into your server.xml file, you can target a specific one by using this Attribute:<br />
e.g.:<br />
&#60;scope service=&#8217;my_engine&#8217;/&#62;</p>
<p>Obviously you can combine scope Attributes together e.g.:<br />
&#60;scope service=&#8217;my_service&#8217; engine=&#8217;my_engine&#8217;/&#62;</p>
<p>host = &#60;HOSTNAME&#62;</p>
<p><em>This value is used either to setup a subset of configuration entries directly under<br />
the host level into the the &#60;CATALINA_BASE&#62;/conf/server.xml or under the &#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/*.xml file.<br />
If not provided the default value is localhost, it is used for sub dependant scopes.<br />
To force the default for this Scope alone force the host value to<br />
&#8220;*default&#8221;.</em></p>
<p>If you have many host entries into your server.xml file, you can target a specific one by using this Attribute:<br />
e.g.:<br />
&#60;scope host=&#8217;my_host&#8217;/&#62;</p>
<p>Obviously you can combine scope Attributes together e.g.:<br />
&#60;scope service=&#8217;my_service&#8217; engine=&#8217;my_engine&#8217; host=&#8217;my_host&#8217;/&#38;glt;</p>
<p><strong>A sample with the tom.alog Action:</strong><br />
In a directory of your choice edit a file named: tom.alog.xml<br />
e.g.:<br />
<code style="color:#990099;">$ vi /home/neil/tom.alog.xml</code><br />
And set its content to:</p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope host='*default'/&#62;
	&#60;/alog&#62;</pre>
<p>Run:<br />
<code style="color:#990099;">$ kikact -c /home/neil tom.alog -v4</code></p>
<p>This creates the following entry into my server.xml,<br />
at node Service@name:Catalina/Engine@name:Catalina/Host@name:localhost :<br />
&#60;Valve className=&#8217;org.apache.catalina.valves.AccessLogValve&#8217; directory=&#8217;/webapp/invoices/logs&#8217;/&#62;</p>
<p><strong>d) context: &#60;CONTEXT_NAME&#62;</strong></p>
<p><em>The value is a Tomcat Context name.<br />
&#8216;*blank&#8217; is the default (aka ROOT) context.<br />
This Attribute can be used in conjunction with all other scopes (except context.default.*).<br />
If set and context.global:true,\<br />
the target is the Context node with name:CONTEXT_NAME within the<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/server.xml file.<br />
Else the target is the file named<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/&#60;CONTEXT_NAME&#62;.xml</em></p>
<p><strong>To target a specific context type:</strong><br />
e.g.:<br />
&#60;scope context=&#8217;my_context&#8217;/&#62;</p>
<p><strong>Sample with defaults :</strong></p>
<p>Edit the file tom.alog.xml</p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope context='*blank'/&#62;
	&#60;/alog&#62;</pre>
<p>Run:<br />
<code style="color:#990099;"> $ kikact -c /home/neil tom.alog -v4</code></p>
<p>This sample targets the node: &#8220;Context&#8221;,<br />
into the file &#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/ROOT.xml.</p>
<p>Note:<br />
&#8212;&#8211;<br />
When scope@service is not provided and if there is only one &#8220;service&#8221; node instance into the file server.xml it is taken as default.<br />
When scope@engine is not provided and if there is only one &#8220;engine&#8221; node instance into the file server.xml under the previous service node, it is taken as default.<br />
When scope@host is not provided its turned to localhost as default.</p>
<p>Because I kept the default Tomcat server.xml file, my values are :<br />
- service : Catalina<br />
- engine : Catalina<br />
And host is set to : localhost</p>
<p>So the target file is for me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/Catalina/localhost/ROOT.xml.</p>
<p>Where I find this entry :<br />
&#60;Valve className=&#8217;org.apache.catalina.valves.AccessLogValve&#8217; directory=&#8217;/webapp/invoices/logs&#8217;/&#62;<br />
under the &#8220;Context&#8221; node.</p>
<p><strong>Explicit sample :</strong></p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope engine='my_engine' host='my_host' context='my_context'/&#62;
	&#60;/alog&#62;</pre>
<p>This sample targets the node: &#8220;Context&#8221;,<br />
into the file &#60;CATALINA_BASE&#62;/conf/my_engine/my_host/my_context.xml.</p>
<p>For me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/my_engine/my_host/my_context.xml</p>
<p><strong>e) context.global: &#60;true/false&#62;</strong></p>
<p><em> If true, scope@context must be set.<br />
If true, the target is the Context node with name: CONTEXT_NAME within the file &#60;CATALINA_BASE&#62;/conf/server.xml.</em></p>
<p><strong>Sample with defaults :</strong></p>
<p>This sample targets the &#8220;Context&#8221; node into server.xml with path=&#8221;" (aka *blank).</p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope context='*blank' context.global='true'/&#62;
	&#60;/alog&#62;</pre>
<p>So the target file is for me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/server.xml.</p>
<p>Where I find this entry :<br />
&#60;Valve className=&#8217;org.apache.catalina.valves.AccessLogValve&#8217; directory=&#8217;/webapp/invoices/logs&#8217;/&#62;<br />
under the node Server/Service@name=Catalina/Engine@name=Catalina/Host@name=localhost/Context@path=&#8221;".</p>
<p><strong>Explicit sample :</strong></p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope  cbase='/webapp/invoices' engine='my_engine' host='my_host' context='my_context'/&#62;
	&#60;/alog&#62;</pre>
<p>This sample targets the node: Server/Engine@name=my_engine/Host@name=my_host/Context@path=my_context,<br />
into the file: /webapp/invoices/conf/server.xml.</p>
<p>f) context.default.global: &#60;true/false&#62;</p>
<p><em>If true, the target is the Context node within the file<br />
&#60;CATALINA_BASE&#62;/conf/context.xml.</em></p>
<p><strong>Sample :</strong></p>
<p>This sample targets the &#8220;Context&#8221; node into file :<br />
&#60;CATALINA_BASE&#62;/conf/context.xml.</p>
<p>&#60;alog type = &#8216;action&#8217; directory = &#8216;/webapp/invoices/logs&#8217;&#62;<br />
&#60;scope context.default.global=&#8217;true&#8217;/&#62;<br />
&#60;/alog&#62;</p>
<p>Note:<br />
&#8212;&#8211;<br />
When scope@service is not provided and if there is only one &#8220;service&#8221; node instance into the file server.xml it is taken as default.<br />
When scope@engine is not provided and if there is only one &#8220;engine&#8221; node instance into the file server.xml under the previous service node, it is taken as default.<br />
When scope@host is not provided its turned to localhost as default.</p>
<p>So the target file is for me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/context.xml.</p>
<p>Where I find this entry :<br />
&#60;Valve className=&#8217;org.apache.catalina.valves.AccessLogValve&#8217; directory=&#8217;/webapp/invoices/logs&#8217;/&#62;<br />
under the &#8220;Context&#8221; node.</p>
<p><strong>g) context.default: &#60;true/false&#62;</strong></p>
<p><em> If true, the target is the Context node within the file<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/context.xml.default.xml.</em></p>
<p><strong>Sample :</strong></p>
<pre>	&#60;alog type = 'action' directory = '/webapp/invoices/logs'&#62;
	    &#60;scope context.default='true'/&#62;
	&#60;/alog&#62;</pre>
<p>This sample targets the &#8220;Context&#8221; node into file :<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;/context.xml.default.xml.</p>
<p>Note:<br />
&#8212;&#8211;<br />
When scope@service is not provided and if there is only one &#8220;service&#8221; node instance into the file server.xml it is taken as default.<br />
When scope@engine is not provided and if there is only one &#8220;engine&#8221; node instance into the file server.xml under the previous service node, it is taken as default.<br />
When scope@host is not provided its turned to localhost as default.</p>
<p>So the target file is for me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/Catalina/localhost/context.xml.default.</p>
<p>Where I find this entry :<br />
&#60;Valve className=&#8217;org.apache.catalina.valves.AccessLogValve&#8217; directory=&#8217;/webapp/invoices/logs&#8217;/&#62;<br />
under the &#8220;Context&#8221; node.</p>
<p><strong>h) resources.global: &#60;true/false&#62;</strong></p>
<p><em>If true will force the creation of a Resource node at the Tomcat GlobalNamingResources node of the &#60;CATALINA_BASE&#62;/conf/server.xml.<br />
This is available for all the Resources supported by Kikionf Actions for Tomat (tom.udbrsc, tom.mailrsc, tom.beanrsc, tom.env).</em></p>
<p>As explained by the Tomcat official website at:<br />
<a href="http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html" rel="nofollow">http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html</a> (chapter introduction), Tomcat 5 now support a new generic level to define resources within the server.xml file at :<br />
the &#8220;GlobalNamingResources&#8221; level.<br />
And these resources are not available by subsequent Contexts definition, until they define a ResourceLink tag.</p>
<p>The Kikonf Action allows you to define resources at this level specifying the resources.global=&#8217;true&#8217; attribute.</p>
<p><strong>Sample :</strong></p>
<p>&#60;env type = &#8216;action&#8217; name = &#8216;env/currency&#8217; etype = &#8216;java.lang.Float&#8217;&#62;<br />
&#60;scope context=&#8217;*blank&#8217; resources.global=&#8217;true&#8217;/&#62;<br />
&#60;envrsc value = &#8217;0.01&#8242; override = &#8216;false&#8217;/&#62;<br />
&#60;/env&#62;</p>
<p>This sample targets the &#8220;GlobalNamingResources&#8221; node into file :<br />
/conf/server.xml.</p>
<p>So the target file is for me :<br />
/usr/local/tomcat/Tomcat 5.5/conf/server.xml.</p>
<p>Where I find this entry :<br />
&#60;Environment name=&#8217;env/currency&#8217; value=&#8217;0.01&#8242; override=&#8217;false&#8217; type=&#8217;java.lang.Float&#8217;/&#62;<br />
under the &#8220;GlobalNamingResources&#8221; node.</p>
<p>See also:<br />
&#8212;&#8212;&#8212;<br />
<a title="How to manage Apache Tomcat DataSources with kikonf" href="http://gijeek.wordpress.com/2011/10/25/how-to-manage-apache-tomcat-datasources-with-kikonf/">How to manage Apache Tomcat DataSources with kikonf</a><br />
<a title="How to manage Apache Tomcat Environment entries with kikonf" href="http://gijeek.wordpress.com/2011/10/28/how-to-manage-apache-tomcat-environment-entries-with-kikonf/">How to manage Apache Tomcat Environment entries with kikonf</a><br />
<a title="How to manage Apache Tomcat Java ® Mail Resource with kikonf" href="http://gijeek.wordpress.com/2011/11/01/how-to-manage-apache-tomcat-java-%c2%ae-mail-resource-with-kikonf/">How to manage Apache Tomcat Java Mail Resource with kikonf</a><br />
<a title="How to manage Apache Tomcat Realms with kikonf" href="http://gijeek.wordpress.com/2011/11/03/how-to-manage-apache-tomcat-realms-with-kikonf/">How to manage Apache Tomcat Realms with kikonf</a><br />
<a title="How to manage Apache Tomcat Access Logs with kikonf" href="http://gijeek.wordpress.com/2011/10/23/how-to-manage-apache-tomcat-access-logs-with-kikonf/">How to manage Apache Tomcat Access Logs with kikonf</a><br />
<a title="How to manage Apache Tomcat Catalina Bases with kikonf" href="http://gijeek.wordpress.com/2011/10/24/how-to-manage-apache-tomcat-catalina-bases-with-kikonf/">How to manage Apache Tomcat Catalina Bases with kikonf</a></p>
<p>Trademarks:<br />
___________</p>
<p>&#8220;Python&#8221; is a registered trademark of the Python Software Foundation.<br />
&#8220;Apache&#8221;, &#8220;Apache Tomcat&#8221;, &#8220;Tomcat&#8221; and &#8220;Apache Derby&#8221; are trademarks of the Apache Software Foundation.<br />
&#8220;Linux&#8221; is a trademark registred to Linus Torvalds<br />
&#8220;JBoss Application Server&#8221; is a registered trademark of Red Hat and its affiliates in the U.S. and other countries.</p>
<p>Java is a registred trademark of Oracle and/or its affiliates.<br />
Other names may be trademarks of their respective owners.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[How to manage Apache Tomcat Java ® Mail Resource with kikonf]]></title>
<link>http://gijeek.wordpress.com/2011/11/01/how-to-manage-apache-tomcat-java-%c2%ae-mail-resource-with-kikonf/</link>
<pubDate>Tue, 01 Nov 2011 16:26:42 +0000</pubDate>
<dc:creator>Neil Rekoswkajab</dc:creator>
<guid>http://gijeek.wordpress.com/2011/11/01/how-to-manage-apache-tomcat-java-%c2%ae-mail-resource-with-kikonf/</guid>
<description><![CDATA[This tutorial shows how to use the Kikonf Actions: tom.mailrsc to configure Tomcat Java Mail Resourc]]></description>
<content:encoded><![CDATA[<p><span style="font-size:120%;">This tutorial shows how to use the Kikonf Actions: <em><strong>tom.mailrsc</strong></em> to configure <strong>Tomcat Java Mail Resources</strong>.</span></p>
<p>I ran this sample on Linux ®, but this works for any Python ® compliant O.S.</p>
<p><strong>I. Before to start</strong></p>
<p><strong>a) Apache Tomcat installation</strong><br />
You should have Apache Tomcat &#62;= 5.5 binary installed on your system.</p>
<p><strong>b) Python installation</strong><br />
Python &#62;=2.4.3 &#60; 3 should also be installed.<br />
If not download it from <a title="download python" href="http://www.python.org" target="_blank">www.python.org</a></p>
<p><strong>c) Kikonf installation</strong><br />
If you have not already installed kikonf</p>
<p>Go to <a title="download kikonf" href="http://www.kikonf.org/download.en.html" target="_blank">www.kikonf.org/download.en.html</a> and download the binary</p>
<p>Uncompress the file into some directory.<br />
You should get something like: <code style="color:#990099;">&#60;my_directory&#62;/kikonf-#-#</code><br />
I choose to install it at <code style="color:#990099;">/usr/local/kikonf-5.2.</code></p>
<p>Set the Kikonf binary path to your PATH environment variable.<br />
e.g:<br />
<code style="color:#990099;">export PATH=$PATH:/usr/local/kikonf-5.2/bin</code></p>
<p>Typing:<br />
<code style="color:#990099;">$ kikact -h </code><br />
or<br />
<code style="color:#990099;">$ kikact -H</code><br />
should show the kikact help.</p>
<p><strong><br />
II. Edit the kikonf.attrs file to use your Tomcat binary installation</strong></p>
<p>Go to the Kikonf conf directory: <code style="color:#990099;">&#60;my_directory&#62;/kikonf-#-#/conf</code></p>
<p><code style="color:#990099;">$ cd /usr/local/kikonf-5.2/conf</code></p>
<p>And change the following lines to match the paths of your WebSphere installation:</p>
<pre style="overflow:auto;"># TOM : Tomcat (R) Injector #
#---------------------------#
software_tom_version = 5.5
software_tom_catalina_home = /usr/local/tomcat/Tomcat 5.5 # The tomcat Installation Directory.
# software_tom_catalina_base = /usr/local/tomcat/invoices
# (Optional) If software_tom_catalina_base is not specified, it take is value from software_tom_catalina_home.
# Note : software_tom_catalina_base can be overwrite by the tag scope/cbase in tom action files.
# software_tom_with_backup = True # (Optional, Default True) Do we backup the original files for the set of files updated at each configuration Session ?
# software_tom_backup_dir = /where/is/backup/dir # (Optional) Where to save the backuped files (If not the temp_dir is used).
# software_tom_record = False # (Optional, Default False) Do we want to record each configuration Session ?</pre>
<p><!--more--><br />
<strong><br />
III. Creating a Tomcat Java (*) Mail Resource</strong></p>
<p>In a directory of your choice edit a file named:<code> tom.mailrsc.xml</code><br />
e.g.:<br />
<code style="color:#990099;">$ vi /home/neil/tom.mailrsc.xml</code></p>
<p>And set its content to:</p>
<pre style="overflow:auto;">
&#60;mailrsc
    type = 'action'
    name = 'mail/mymail'
&#62;
    &#60;scope context='*blank' context.global='true'/&#62;
    &#60;resource auth = 'false' host = 'mail.intra.net'/&#62;    

&#60;/mailrsc&#62;
</pre>
<p>Run:<br />
<code style="color:#990099;">$ kikact -c /home/neil tom.mailrsc -v4</code></p>
<pre style="overflow:auto;">kikact -c /home/neil  tom.mailrsc -v4

Begin Actions ...

picxmlp: Parsing file: /home/neil/tom.mailrsc.xml.
picxmlp: Parsing file: /usr/local/kikonf-5.2/kikonf-5.2/plugins/actions/tom/mailrsc/by/kikonf/ACT_INF/action.xml.
Begin Actions ...

Action:mailrsc retrieved.
   Inject Operation

      Mailrsc at scope: context.global
         cbase: /usr/local/tomcat/Tomcat 5.5
         context.global: true
         context:

         Java Mail Resource:mail/mymail Removing.
         Java Mail Resource:mail/mymail Creating.
         Java Mail Resource:mail/mymail Created.

... End Actions

File:/usr/local/tomcat/Tomcat 5.5/conf/server.xml saved !</pre>
<p>This creates the following entry into my server.xml,<br />
at node Service@name:Catalina/Engine@name:Catalina/Host@name:localhost/Context@path:&#8221; :<br />
&#60;Resource name=&#8217;mail/mymail&#8217; auth=&#8217;Application&#8217; mail.smtp.host=&#8217;mail.intra.net&#8217; type=&#8217;javax.mail.Session&#8217;/&#62;</p>
<p><strong>IV. Creating a Tomcat DataSource as global resource and using it</strong></p>
<p>As explained by the Tomcat official website at:<br />
<a href="http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html" target="_blank">http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html</a> (chapter introduction),<br />
Tomcat 5 now support a new generic level to define resources within the server.xml file at :<br />
the &#8220;GlobalNamingResources&#8221; level.<br />
And these resources are not available by subsequent Contexts definition, until they define a<br />
ResourceLink tag.</p>
<p>The Kikonf Actions allows you to define resources at this level specifying the<br />
resources.global=&#8217;true&#8217; attribute.</p>
<p>In the same directory of your choice edit a file named: tom.mailrsc.$rg.xml<br />
e.g.:<br />
<code style="color:#990099;">$ vi /home/neil/tom.mailrsc.$rg.xml</code></p>
<p>And set its content to:</p>
<pre style="overflow:auto;">
&#60;mailrsc
    type = 'action'
    name = 'mail/mymail'
&#62;
    &#60;scope context='*blank' context.global='true' resources.global='true'/&#62;  
    &#60;resource auth = 'false' host = 'mail.intra.net'/&#62;   

    &#60;link name = 'mail/local_name'/&#62;
    
&#60;/mailrsc&#62;</pre>
<p>Run:<br />
<code style="color:#990099;">$ kikact -c /home/neil tom.mailrsc.$rg -v4</code></p>
<pre style="overflow:auto;">picxmlp: Parsing file: /home/neil/tom.mailrsc.$rg.xml.
picxmlp: Parsing file: /usr/local/kikonf-5.2/kikonf-5.2/plugins/actions/tom/mailrsc/by/kikonf/ACT_INF/action.xml.
Begin Actions ...

Action:mailrsc (tom.mailrsc.$rg) retrieved.
   Inject Operation

      Mailrsc at scope: context.global
         cbase: /usr/local/tomcat/Tomcat 5.5
         context.global: true
         context:
         resources.global: true

         Java Mail ResourceLink:mail/mymail Removing.
         Java Mail ResourceLink:mail/mymail Creating.
         Java Mail ResourceLink:mail/mymail Created.
         Java Mail Resource:mail/mymail Removing.
         Java Mail Resource:mail/mymail Creating.
         Java Mail Resource:mail/mymail Created.

... End Actions

File:/usr/local/tomcat/Tomcat 5.5/conf/server.xml saved !</pre>
<p>This creates the following 2 entries into my server.xml :</p>
<p>- at the &#8220;GlobalNamingResources&#8221; level:<br />
&#60;Resource name=&#8217;mail/mymail&#8217; auth=&#8217;Application&#8217; mail.smtp.host=&#8217;mail.intra.net&#8217; type=&#8217;javax.mail.Session&#8217;/&#62;<br />
- at node Service@name:Catalina/Engine@name:Catalina/Host@name:localhost/Context@path:&#8221; :<br />
&#60;ResourceLink global=&#8217;mail/mymail&#8217; name=&#8217;mail/local_name&#8217; type=&#8217;javax.mail.Session&#8217;/&#62;</p>
<p>Note:<br />
&#8212;&#8211;<br />
This scope@resources.global facility is available for all the Resources supported by Kikonf Actions for Tomcat (tom.udbrsc, tom.mailrsc, tom.beanrsc, tom.env).</p>
<p><strong>V. Handling scopes</strong></p>
<p>This is a short example of the way of using the scope tag to target a Tomcat specific<br />
scope.</p>
<p>To clearly understand the potential of this tag see the scope tutorial at:<br />
==&#62; Link sur tom.scopes</p>
<p>In the same directory of your choice edit a file named: <code>tom.mailrsc.$scope.xml</code><br />
e.g.:<br />
<code style="color:#990099;">$ vi /home/neil/tom.mailrsc.$scope.xml</code></p>
<p>And set its content to:<br />
&#60;mailrsc<br />
    type = &#8216;action&#8217;<br />
    name = &#8216;mail/mymail&#8217;<br />
&#62;<br />
    &#60;scope context=&#8217;*blank&#8217; resources.global=&#8217;true&#8217;/&#62;<br />
    &#60;resource auth = &#8216;false&#8217; host = &#8216;mail.intra.net&#8217;/&#62;    </p>
<p>    &#60;link name = &#8216;mail/local_name&#8217;/&#62;</p>
<p>&#60;/mailrsc&#62;<br />
Run:<br />
<code style="color:#990099;">$ kikact -c /home/neil tom.mailrsc.$scope -v4</code></p>
<pre style="overflow:auto;">Begin Actions ...

picxmlp: Parsing file: /home/neil/tom.mailrsc.$scope.xml.
picxmlp: Parsing file: /usr/local/kikonf-5.2/kikonf-5.2/plugins/actions/tom/mailrsc/by/kikonf/ACT_INF/action.xml.
Begin Actions ...

Action:mailrsc (tom.mailrsc.$scope) retrieved.
   Inject Operation

      Mailrsc at scope: context
         cbase: /usr/local/tomcat/Tomcat 5.5
         context:
         resources.global: true

         Java Mail ResourceLink:mail/mymail Removing.
         Java Mail ResourceLink:mail/mymail Removed:1 configuration Entry.
         Java Mail ResourceLink:mail/mymail Creating.
         Java Mail ResourceLink:mail/mymail Created.
         Java Mail Resource:mail/mymail Removing.
         Java Mail Resource:mail/mymail Removed:1 configuration Entry.
         Java Mail Resource:mail/mymail Creating.
         Java Mail Resource:mail/mymail Created.

... End Actions

File:/usr/local/tomcat/Tomcat 5.5/conf/Catalina/localhost/ROOT.xml saved !
File:/usr/local/tomcat/Tomcat 5.5/conf/server.xml saved !</pre>
<p>Because scope@resources.global is true,<br />
this creates one entry into my server.xml at the &#8220;GlobalNamingResources&#8221; level:<br />
&#60;Resource name=&#8217;mail/mymail&#8217; auth=&#8217;Application&#8217; mail.smtp.host=&#8217;mail.intra.net&#8217; type=&#8217;javax.mail.Session&#8217;/&#62;</p>
<p>Because scope@context.global is not given, hence false the target file is :<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;ROOT.xml<br />
(for me /usr/local/tomcat/Tomcat 5.5/conf/Catalina/localhost/ROOT.xml)</p>
<p>Where this entry is created at the Context node :<br />
&#60;ResourceLink global=&#8217;mail/mymail&#8217; name=&#8217;mail/local_name&#8217; type=&#8217;javax.mail.Session&#8217;/&#62;</p>
<p>Note:<br />
&#8212;&#8211;<br />
You may also change this path :<br />
&#60;CATALINA_BASE&#62;/conf/&#60;ENGINE_NAME&#62;/&#60;HOSTNAME&#62;ROOT.xml<br />
using :<br />
&#60;scope cbase=&#8217;/another/cbase&#8217; engine=&#8217;my_engine&#8217; host=&#8217;my_host&#8217; context=&#8217;my_context&#8217; resources.global=&#8217;true&#8217;/&#62;<br />
to:<br />
<code style="color:#990099;">/another/cbase/conf/my_engine/my_host/my_context.xml</code></p>
<p>See also:<br />
&#8212;&#8212;&#8211;<br />
<a title="How to manage Apache Tomcat DataSources with&#160;kikonf" href="http://gijeek.wordpress.com/2011/10/25/how-to-manage-apache-tomcat-datasources-with-kikonf/" target="_blank">How to manage Apache Tomcat DataSources with kikonf</a><br />
<a title="How to manage Apache Tomcat Environment entries with&#160;kikonf" href="http://gijeek.wordpress.com/2011/10/28/how-to-manage-apache-tomcat-environment-entries-with-kikonf/" target="_blank">How to manage Apache Tomcat Environment entries with kikonf</a><br />
<a href="http://gijeek.wordpress.com/2011/11/03/how-to-manage-apache-tomcat-realms-with-kikonf/" title="How to manage Apache Tomcat Realms with&#160;kikonf">How to manage Apache Tomcat Realms with kikonf</a><br />
<a href="http://gijeek.wordpress.com/2011/11/07/how-to-manage-apache-tomcat-scopes-with-kikonf/" title="How to manage Apache Tomcat Scopes with kikonf">How to manage Apache Tomcat Scopes with kikonf</a><br />
<a title="How to manage Apache Tomcat Access Logs with&#160;kikonf" href="http://gijeek.wordpress.com/2011/10/23/how-to-manage-apache-tomcat-access-logs-with-kikonf/" target="_blank">How to manage Apache Tomcat Access Logs with kikonf</a><br />
<a title="How to manage Apache Tomcat Catalina Bases with&#160;kikonf" href="http://gijeek.wordpress.com/2011/10/24/how-to-manage-apache-tomcat-catalina-bases-with-kikonf/" target="_blank">How to manage Apache Tomcat Catalina Bases with kikonf</a></p>
<p>Trademarks:<br />
___________<br />
&#8220;Python&#8221; is a registered trademark of the Python Software Foundation.<br />
&#8220;Apache&#8221;, &#8220;Apache Tomcat&#8221;, &#8220;Tomcat&#8221; and &#8220;Apache Derby&#8221; are trademarks of the Apache Software Foundation.<br />
&#8220;Linux&#8221; is a trademark registered to Linus Torvalds<br />
&#8220;JBoss Application Server&#8221; is a registered trademark of Red Hat and its affiliates in the U.S. and other countries.</p>
<p>Java is a registered trademark of Oracle and/or its affiliates.<br />
Other names may be trademarks of their respective owners.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Send Mail using Java Mail API ]]></title>
<link>http://tinyjava.wordpress.com/2011/10/25/send-mail-using-java-mail-api/</link>
<pubDate>Tue, 25 Oct 2011 03:51:05 +0000</pubDate>
<dc:creator>tinyjava</dc:creator>
<guid>http://tinyjava.wordpress.com/2011/10/25/send-mail-using-java-mail-api/</guid>
<description><![CDATA[import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; impo]]></description>
<content:encoded><![CDATA[<p><code>import java.io.*;<br />
import javax.mail.*;<br />
import javax.mail.internet.*;<br />
import javax.activation.*;<br />
import java.util.Properties;<br />
// Class Declaration<br />
public class SendMail {<br />
public SendMail(){<br />
}<br />
// Send Method</code></p>
<p>// hostIp : Mail server IP address,<br />
//from : Mail from address (e.g <a href="mailto:xyz@domain.com">xyz@domain.com</a>)<br />
//to : Mail to address (e.g <a href="mailto:abc@domain.com">abc@domain.com</a>)<br />
//cc : Mail CC address, bcc : mail to bcc address<br />
//subject : mail subject,<br />
//body : mail body,<br />
//filename attachment file name including path<br />
public boolean send(String hostIp,String from,String to,String cc,String bcc,String subject,String body,String filename)<br />
{<br />
String smtpHost=hostIp;<br />
String host=&#8221;";<br />
boolean status=false;<br />
try {<br />
Properties properties = System.getProperties ();<br />
host=smtpHost;<br />
properties.put(&#8220;mail.smtp.host&#8221;, host);<br />
Session session = Session.getInstance(properties, null);<br />
MimeMessage message = new MimeMessage(session);<br />
if(from!=null) {<br />
Address fromAddress = new InternetAddress(from);<br />
message.setFrom(fromAddress);<br />
}<br />
// Parse and set the recipient addresses<br />
if(to!=null) {<br />
Address[] toAddresses = InternetAddress.parse(to);<br />
message.setRecipients(Message.RecipientType.TO,toAddresses);<br />
}<br />
if(cc!=null) {<br />
Address[] ccAddresses = InternetAddress.parse(cc);<br />
message.setRecipients(Message.RecipientType.CC,ccAddresses);<br />
}<br />
if(bcc!=null) {<br />
Address[] bccAddresses = InternetAddress.parse(bcc);<br />
message.setRecipients(Message.RecipientType.BCC,bccAddresses);<br />
}<br />
// Set the subject and Body<br />
message.setSubject(subject);<br />
// Attach file with message<br />
if(filename.equals(null)&#124;&#124;filename.equals(&#8220;&#8221;))<br />
{<br />
/* MimeBodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setText(body);*/<br />
BodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setContent(body, &#8220;text/html&#8221;);<br />
// create the Multipart and its parts to it<br />
Multipart mp = new MimeMultipart();<br />
mp.addBodyPart(mbp1);<br />
// add the Multipart to the message<br />
message.setContent(mp);<br />
}<br />
else<br />
{<br />
File file = new File(filename);<br />
if(file.exists())<br />
{<br />
/*MimeBodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setText(body);*/<br />
BodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setContent(body, &#8220;text/html&#8221;);<br />
// create the second message part<br />
MimeBodyPart mbp2 = new MimeBodyPart();<br />
// attach the file to the message<br />
FileDataSource fds = new FileDataSource(filename);<br />
mbp2.setDataHandler(new DataHandler(fds));<br />
mbp2.setFileName(fds.getName());<br />
// create the Multipart and its parts to it<br />
Multipart mp = new MimeMultipart();<br />
mp.addBodyPart(mbp1);<br />
mp.addBodyPart(mbp2);<br />
// add the Multipart to the message<br />
message.setContent(mp);<br />
}<br />
else<br />
{<br />
/* MimeBodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setText(body);  */<br />
BodyPart mbp1 = new MimeBodyPart();<br />
mbp1.setContent(body, &#8220;text/html&#8221;);<br />
// create the Multipart and its parts to it<br />
Multipart mp = new MimeMultipart();<br />
mp.addBodyPart(mbp1);<br />
// add the Multipart to the message<br />
message.setContent(mp);<br />
}<br />
}<br />
// send the message<br />
Transport.send(message);<br />
status =true;<br />
}catch (AddressException e){<br />
status = false;<br />
System.out.println(&#8220;Address field found corrupted.&#8221;);<br />
}catch (SendFailedException e){<br />
status = false;<br />
System.out.println(&#8220;Unknown SMTP host: &#8220;+host);<br />
}catch (MessagingException e) {<br />
status = false;<br />
System.out.println(&#8220;Could not connect to SMTP host:&#8221;+host);<br />
}catch (Exception e) {<br />
status = false;<br />
System.out.println(&#8220;Could not connect to SMTP host:&#8221;+host);<br />
}<br />
return status;<br />
}<br />
public static void main(String[] args)  {<br />
SendMail sendmail = new SendMail();<br />
boolean t=sendmail.send(&#8220;your mail server IP&#8221;,&#8221;<a href="mailto:mailfrom@domain.com,mailto@domain.com,%22%22,%22%22,%27Subject%27,">mailto:mailfrom@domain.com,mailto@domain.com,&#8221;",&#8221;",&#8221;Subject&#8221;,</a>&#8220;body&#8221;,&#8221;c://abc.jpeg&#8221;);<br />
System.out.print(t);<br />
}<br />
}</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Send Mail with Gmail]]></title>
<link>http://mhjeridi.wordpress.com/2011/08/22/java-sendmail-with-gmail/</link>
<pubDate>Mon, 22 Aug 2011 12:31:21 +0000</pubDate>
<dc:creator>MHJ</dc:creator>
<guid>http://mhjeridi.wordpress.com/2011/08/22/java-sendmail-with-gmail/</guid>
<description><![CDATA[/** * */ package org.dagchrono.utilities; import java.util.Properties; import javax.mail.Authenticat]]></description>
<content:encoded><![CDATA[<pre class="brush: java; title: ; notranslate" title="">
/**
 * 
 */
package org.dagchrono.utilities;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * @author Mohamed.hechmi.jeridi@gmail.com
 * 
 */
public class SendMail {

	private static String USERNAME = &#34;you_account@gmail.com&#34;;
	private static String PASSWORD = &#34;password&#34;;
	private static String SMTP_HOST = &#34;smtp.gmail.com&#34;;
	private static int PORT = 465;

	public void sendPlainText(String to, String subject, String msg) throws MessagingException {

		Properties props = new Properties();
		props.put(&#34;mail.smtp.user&#34;, USERNAME);
		props.put(&#34;mail.smtp.host&#34;, SMTP_HOST);
		props.put(&#34;mail.smtp.port&#34;, PORT);
		props.put(&#34;mail.smtp.starttls.enable&#34;, &#34;true&#34;);
                props.put(&#34;mail.smtp.debug&#34;, &#34;true&#34;);
		props.put(&#34;mail.smtp.auth&#34;, &#34;true&#34;);
		props.put(&#34;mail.smtp.socketFactory.port&#34;, PORT);
		props.put(&#34;mail.smtp.socketFactory.class&#34;,&#34;javax.net.ssl.SSLSocketFactory&#34;);
		props.put(&#34;mail.smtp.socketFactory.fallback&#34;, &#34;false&#34;);
		SMTPAuthenticator auth = new SMTPAuthenticator();
		Session session = Session.getInstance(props, auth);
		session.setDebug(true);
		Message message = new MimeMessage(session);
		message.setText(msg);
		message.setSubject(subject);
		message.setFrom(new InternetAddress(USERNAME));
		message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
		Transport.send(message);
	}

	private class SMTPAuthenticator extends Authenticator {
		public PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(USERNAME, PASSWORD);
		}
	}

}

</pre>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Command Line Mass Mailing Tool]]></title>
<link>http://opensourceenterprise.wordpress.com/2011/06/19/command-line-mass-mailing-tool-3/</link>
<pubDate>Sun, 19 Jun 2011 08:45:00 +0000</pubDate>
<dc:creator>Mantavya Gajjar</dc:creator>
<guid>http://opensourceenterprise.wordpress.com/2011/06/19/command-line-mass-mailing-tool-3/</guid>
<description><![CDATA[There are lots of tool for mass-mailing, but this tool is the tool for which i am talking about is b]]></description>
<content:encoded><![CDATA[<p><a href="http://opensourceenterprise.files.wordpress.com/2011/06/massmailing2.jpg"><img class="alignright" src="http://opensourceenterprise.files.wordpress.com/2011/06/massmailing2.jpg?w=139&#038;h=108" alt="" width="139" height="108" border="0" /></a>There are lots of tool for mass-mailing, but this tool is the tool for which i am talking about is based on command line. It is a very simple tool with as much as configurations for <a class="zem_slink" title="Application software" href="http://en.wikipedia.org/wiki/Application_software" rel="wikipedia" target="_blank">applications</a> and mail framework properties.</p>
<h3><a class="zem_slink" title="Application Settings" href="http://www.facebook.com/editapps.php" rel="homepage" target="_blank">Application Settings</a></h3>
<p>All application configurations will be given through the application.properties where you have to provide the settings like password, email list file, email file, return path, log file, debug option, mailer and mail format like text, html, etc..</p>
<h3>Email Settings</h3>
<p>Email settings file mainly contains all email settings which required by the Java Mailing apis, you may fine complete properties list here. some of the important properties ate are host, port, user name etc..</p>
<div class="wp-caption aligncenter" style="width: 330px"><a href="http://opensourceenterprise.files.wordpress.com/2011/06/massmail5.png"><img style="border:0;" title="Application folder - contains all files" src="http://opensourceenterprise.files.wordpress.com/2011/06/massmail5.png?w=320&#038;h=158" alt="Application folder - contains all files" width="320" height="158" border="0" /></a><p class="wp-caption-text"><a class="zem_slink" title="Application Base" href="http://www.techopedia.com/definition/25165/application-base-net" rel="techopedia" target="_blank">Application folder</a> &#8211; contains all files</p></div>
<p><!--more--></p>
<h3>Setup <a class="zem_slink" title="Electronic mailing list" href="http://en.wikipedia.org/wiki/Electronic_mailing_list" rel="wikipedia" target="_blank">Email List</a></h3>
<p>Application property `application.list` used to pass the email list to the application. This file heaving a very simple format one line is equals to one <a class="zem_slink" title="Email address" href="http://en.wikipedia.org/wiki/Email_address" rel="wikipedia" target="_blank">email address</a>. it means if you wanted to send email to 1000 people you have create 1000 lines in this file and place the complete path of that file in application.list parameter. default file is list.txt its already there with the program.</p>
<h3>Setup Email</h3>
<p>Application property `application.email` used to pass the email data to the application. You can write Text or <a class="zem_slink" title="HTML" href="http://en.wikipedia.org/wiki/HTML" rel="wikipedia" target="_blank">HTML</a> data in that file for the movement it does not support any attachments.</p>
<h3>Setting <a class="zem_slink" title="Host (network)" href="http://en.wikipedia.org/wiki/Host_%28network%29" rel="wikipedia" target="_blank">Host</a> and <a class="zem_slink" title="Port number" href="http://en.wikipedia.org/wiki/Port_number" rel="wikipedia" target="_blank">Port</a></h3>
<p>Host and port both settings are related to the Email framework configurations, you may find the properties mail.smtp.host and mail.smtp.port in the email configurations. it varies based on which <a class="zem_slink" title="Simple Mail Transfer Protocol" href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol" rel="wikipedia" target="_blank">smtp server</a> you are using. Here i have used an yahoo smtp server.</p>
<h3>Setting <a class="zem_slink" title="User (computing)" href="http://en.wikipedia.org/wiki/User_%28computing%29" rel="wikipedia" target="_blank">User</a> and Password</h3>
<p>User and password are related to the different configurations, user is comes from the mail configurations while password is comes from the application configurations, as because mail configuration is a set of standard properties of Java <a class="zem_slink" title="Messaging Application Programming Interface" href="http://en.wikipedia.org/wiki/Messaging_Application_Programming_Interface" rel="wikipedia" target="_blank">Mail API</a> not contains the property for the password. If you plan to send email using user/password authentication then mail.smtp.auth property must be set to true or else set to false if you plan to send email using local smtp program like sendmail.</p>
<h3>Run Mass mail</h3>
<p>Once you ready with all configurations, you just need to execute either run.sh or run.bat depending on your operating system. and It will start throwing email to the and logging the same in the logfile. Have a look at the sample run below.</p>
<h3>Download</h3>
<p><a href="https://sites.google.com/site/mgatiny/massmail.zip?attredirects=0&#38;d=1">Click here to download the Application</a></p>
<h3>Sample Run</h3>
<p>mantavya@mga-laptop:~$ cd Desktop/massmail/<br />
mantavya@mga-laptop:~/Desktop/massmail$ ./run.sh<br />
19 Jun, 2011 1:30:19 PM in.mantavyagajjar.massmail.MailManager loadProperties<br />
INFO: Read application settings application.properties successfully !<br />
19 Jun, 2011 1:30:19 PM in.mantavyagajjar.massmail.MailManager loadProperties<br />
INFO: Read mail settings mail.properties successfully !<br />
19 Jun, 2011 1:30:19 PM in.mantavyagajjar.massmail.MailManager<br />
INFO: Session created successfully !<br />
19 Jun, 2011 1:30:19 PM in.mantavyagajjar.massmail.MailManager run<br />
INFO: Reading emaillist list.txt successfully !<br />
19 Jun, 2011 1:30:19 PM in.mantavyagajjar.massmail.MailManager run<br />
INFO: Reading e-mail from email.txt successfully !<br />
19 Jun, 2011 1:30:22 PM in.mantavyagajjar.massmail.MailManager run<br />
INFO: Email sent successfully &#8211; mantavyagajjar@gmail.com</p>
		<div id="geo-post-1978" class="geo geo-post" style="display: none">
			<span class="latitude">23.206078</span>
			<span class="longitude">72.631379</span>
		</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Must issue a STARTTLS command first" while sending email]]></title>
<link>http://key2start.wordpress.com/2011/05/11/must-issue-a-starttls-command-first-while-sending-email/</link>
<pubDate>Wed, 11 May 2011 09:29:39 +0000</pubDate>
<dc:creator>Creators</dc:creator>
<guid>http://key2start.wordpress.com/2011/05/11/must-issue-a-starttls-command-first-while-sending-email/</guid>
<description><![CDATA[When encountered this type of error when sending email with java mail feature, just set the below me]]></description>
<content:encoded><![CDATA[<p>When encountered this type of error when sending email with java mail feature, just set the below mentioned attribute to the Properties object you are using before,</p>
<p><span style="color:#3366ff;"><strong>Properties props = System.getProperties();</strong></span></p>
<p>.</p>
<p>.</p>
<p><span style="color:#3366ff;"><strong>.</strong></span></p>
<div><span style="color:#3366ff;"><strong>props.put(&#8220;mail.smtp.starttls.enable&#8221;,&#8221;true&#8221;);</strong></span></div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Attaching excel or pdf files to a mail using spring framework ]]></title>
<link>http://gauravmutreja.wordpress.com/2010/09/01/attaching-excel-or-pdf-files-to-a-mail-using-spring-framework/</link>
<pubDate>Wed, 01 Sep 2010 21:41:30 +0000</pubDate>
<dc:creator>Gaurav Mutreja</dc:creator>
<guid>http://gauravmutreja.wordpress.com/2010/09/01/attaching-excel-or-pdf-files-to-a-mail-using-spring-framework/</guid>
<description><![CDATA[Few days back I got a requirement which said that I need to generate and display and excel file to t]]></description>
<content:encoded><![CDATA[<p>Few days back I got a requirement which said that I need to generate and display and excel file to the user . I used  java excel API JExecl which I found out was in fact quite interesting. You can add cells to them , define cell types , cell fonts and other stuffs.So , for creating excel file in java  Jexcel API are decent enough.</p>
<p>Now the second thing which I needed to do was to send the excel file as an attachment in a mail to the user. My existing code used to support the text mail sending part but now I have to attach the excel file to it. I had generated an array of bytes to dispaly in excel file and now I wanted to use this byte array to be sent as an excel attachment.<br />
When I googled I found solutions majorly related to wiring the file on disk as temp.xls and then reading the file , attaching it and then deleting the temp file which was actually I what I was trying to  avoid as I have never done file handling and some how I am bit scared of file I/O APIs.<br />
<!--more--><br />
Since I was using spring framework , we were using mimeMessageHelper for mails. I looked into the API&#8217;s and found out that it also supports attachment with mails and that even without using file I/O  I was able to use my array of bytes.<br />
But there were few problems at first due to InputStreamSource class as I never used it before. Moreover, I did not find a single article on internet which described the whole process with a complete working example. So, I had to hop from one place to another on web to finally get to the solution.</p>
<p>I guess its a very general problem which many people would encounter, so I am giving a sample code which I will explain a bit also.</p>
<p>*******************************************************************************</p>
<p>public void sendBulkAttachMentTextEmail(final Collection&#60;String&#62; to, final String from,<br />
final String subject, final String emailText,final byte[] byteArray)<br />
throws MailServiceException {<br />
MimeMessagePreparator preparator = new MimeMessagePreparator() {<br />
public void prepare(MimeMessage mimeMessage) throws Exception {</p>
<p><strong>MimeMessageHelper message = new MimeMessageHelper(mimeMessage,true);</strong></p>
<p>// Get the array to addresses.<br />
Object[] toAddresses = to.toArray();<br />
int noOfRecipients = toAddresses.length;<br />
String[] addressTo = new String[noOfRecipients];<br />
for (int i = 0; i &#60; noOfRecipients; i++) {<br />
addressTo[i] = (String) toAddresses[i];<br />
}</p>
<p>//Set message To address list.<br />
message.setTo(addressTo);<br />
logger.info(&#8220;Recipient : &#8221; + addressTo);<br />
//Set email from address.<br />
message.setFrom(from);<br />
logger.info(&#8220;Sender : &#8221; + from);<br />
//Set email subject<br />
message.setSubject(subject);<br />
logger.info(&#8220;Subject : &#8221; + subject);</p>
<p>//parse the template and replace the variable values.<br />
freeMarkerConfig.clearTemplateCache();<br />
/*Template mailTemplate = freeMarkerConfig.getTemplate(template);<br />
String text = FreeMarkerTemplateUtils<br />
.processTemplateIntoString(mailTemplate, params);*/</p>
<p>logger.info(&#8220;Email Content : &#8220;);<br />
//Set the email text.<br />
logger.info(emailText);<br />
message.setText(emailText, true);<br />
<strong><br />
ByteArrayResource bar = new ByteArrayResource(byteArray);</strong></p>
<p><strong>message.addAttachment(&#8220;Report.xls&#8221;,bar,&#8221;application/vnd.ms-excel &#8220;);</strong></p>
<p>}<br />
};</p>
<p>}</p>
<p>**************************************************************************</p>
<p>You must set the boolean to true in MimemessageHelper constructor. It means that you are defining the mail to be multipart.</p>
<p>Now Spring provides different class implementing InputStreamSource . Since I had the array of bytes I created an instance of ByteArrayResource with the argument in constructor as my byte[]. Lastly you need to define the report name and its type while attaching the ByterArrayResource instance and then you can send the mail.</p>
<p>I guess this information may be useful for people looking for this kind of task and if you have any questions you can put in your comments over here and I would revert back.</p>
<p>Thanks</p>
<p>Gaurav Mutreja</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Sample Code - For E-Mailing Through Java -- Send Mail single part , multipart , attachment , html  (Part 1)]]></title>
<link>http://ashishladdha.wordpress.com/2009/07/21/sample-code-for-e-mailing-through-java-send-mail-single-part-multipart-attachment-html-part-1/</link>
<pubDate>Tue, 21 Jul 2009 08:14:50 +0000</pubDate>
<dc:creator>ashishladdha</dc:creator>
<guid>http://ashishladdha.wordpress.com/2009/07/21/sample-code-for-e-mailing-through-java-send-mail-single-part-multipart-attachment-html-part-1/</guid>
<description><![CDATA[This Post will show you how to send  emails through java program using JAVA Mail API. Download mail.]]></description>
<content:encoded><![CDATA[<p>This Post will show you how to send  emails through java program using JAVA Mail API.</p>
<p>Download <strong>mail.jar</strong> and <strong>activation.jar</strong>,  and add them in the java class path to compile and run the code.</p>
<p><strong>Sample Code for Single Part plain/text Email :</strong></p>
<pre>import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

// Send a simple, single part, text/plain e-mail
public class SendTestEmail {

    public static void main(String[] args) {

        // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
        String to = "&#60;usrname@domain.com&#62;"; <span style="color:#ff0000;">// i.e. ashish@gmail.com</span>
        String from = "&#60;username@domain.com&#62;"; <span style="color:#ff0000;">//i.e ashish@gmail.com</span>
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        String host = "&#60;host name&#62;"; <span style="color:#ff0000;"> // i.g smtp.gmail.com for gmail</span>

        // Create properties, get Session
        Properties props = new Properties();

        // If using static Transport.send(),
        // need to specify which host to send it to
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        props.put("mail.debug", "true");  <span style="color:#ff0000;">// I have set debug  TRUE to see whats going on inside the JAVA MAIL. If you don'd need it turn it off.</span>
        Session session = Session.getInstance(props);

        try {
            // Instantiatee a message
            Message msg = new MimeMessage(session);

            //Set message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("Test E-Mail through Java");
            msg.setSentDate(new Date());

            // Set message content
            msg.setText("This is a test of sending a " +
                        "plain text e-mail through Java.\n" +
                        "Here is line 2.");

            //Send the message
            Transport.send(msg);
        }
        catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
        }
    }
}//End of class

 </pre>
<p>Now compile and run the program after changing the Email addresses and Mail Server Address.</p>
<p> This is the example of single part ,text.plain email. Now we will see a sample code for send mails <strong>having Multipart, Attachments or HTML contents</strong>.</p>
<p><strong>Sample Code for  Multipart , HTML, Attachment Emails :</strong></p>
<pre>import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendTestEmail{
   private static final String SMTP_HOST_NAME = "&#60;host name&#62;";  <span style="color:#ff0000;">//i.g. smtp.gmail.com
</span>     private static final String SMTP_PORT = "465"; 
     private static final String emailFromAddress = "&#60;userNameFrom@domain.com&#62;";   <span style="color:#ff0000;">//i.g. </span><a href="mailto:ashish@gmail.com"><span style="color:#ff0000;">ashish@gmail.com</span></a>
     private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; 
     private static final String sendTo = "&#60;userNameTo@domain.com&#62;" ; <span style="color:#ff0000;"> //i.g. </span><a href="mailto:ashish@gmail.com"><span style="color:#ff0000;">ashish@gmail.com</span></a>
<span style="color:#ff0000;">   
</span> public static void main(String[] args) {
          Properties props = new Properties(); 
          props.put("mail.smtp.host", SMTP_HOST_NAME); 
          props.put("mail.smtp.auth", "true"); 
          props.put("mail.debug", "true"); 
          props.put("mail.smtp.port", SMTP_PORT); 
          props.put("mail.smtp.socketFactory.port", SMTP_PORT); 
          props.put("mail.smtp.socketFactory.class", SSL_FACTORY); 
          props.put("mail.smtp.socketFactory.fallback", "false"); 
   
          props.put("mail.smtp.starttls.enable","true"); 
  // Get a session
  Session session = Session.getInstance(props);
  try {
   // Get a Transport object to send e-mail
   Transport bus = session.getTransport("smtp");
   bus.connect(SMTP_HOST_NAME, emailFromAddress, "changeme");
   // Instantiate a message
   Message msg = new MimeMessage(session);
   // Set message attributes
   msg.setFrom(new InternetAddress(emailFromAddress));
   InternetAddress[] address = { new InternetAddress(sendTo) };
   msg.setRecipients(Message.RecipientType.TO, address);
   // Parse a comma-separated list of email addresses. Be strict.
   msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(
     sendTo, true));
   // Parse comma/space-separated list. Cut some slack.
   msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(
     sendTo, false));
   msg.setSubject("Test E-Mail through Java");
   msg.setSentDate(new Date());
   // Set message content and send
   //Send Multipart Eamil Message
   setMultipartContent(msg);
   msg.saveChanges();
   bus.sendMessage(msg, address);
   //Send Email with Attachment
   setFileAsAttachment(msg, "&#60;file path&#62;");
   msg.saveChanges();
   bus.sendMessage(msg, address);
   // Send HTML email
   setHTMLContent(msg);
   msg.saveChanges();
   bus.sendMessage(msg, address);
   bus.close();
  } catch (MessagingException mex) {
   // Prints all nested (chained) exceptions as well
   mex.printStackTrace();
   // How to access nested exceptions
   while (mex.getNextException() != null) {
    // Get next exception in chain
    Exception ex = mex.getNextException();
    ex.printStackTrace();
    if (!(ex instanceof MessagingException))
     break;
    else
     mex = (MessagingException) ex;
   }
  }
 }
 // A simple, single-part text/plain e-mail.
 public static void setTextContent(Message msg) throws MessagingException {
  // Set message content
  String mytxt = "This is a test of sending a "
    + "plain text e-mail through Java.\n" + "Here is line 2.";
  msg.setText(mytxt);
  // Alternate form
  msg.setContent(mytxt, "text/plain");
 }
 // A simple multipart/mixed e-mail. Both body parts are text/plain.
 public static void setMultipartContent(Message msg)
   throws MessagingException {
  // Create and fill first part
  MimeBodyPart p1 = new MimeBodyPart();
  p1.setText("This is part one of a test multipart e-mail.");
  // Create and fill second part
  MimeBodyPart p2 = new MimeBodyPart();
  // Here is how to set a charset on textual content
  p2.setText("This is the second part", "us-ascii");
  // Create the Multipart. Add BodyParts to it.
  Multipart mp = new MimeMultipart();
  mp.addBodyPart(p1);
  mp.addBodyPart(p2);
  // Set Multipart as the message's content
  msg.setContent(mp);
 }
 // Set a file as an attachment. Uses JAF FileDataSource.
 public static void setFileAsAttachment(Message msg, String filename)
   throws MessagingException {
  // Create and fill first part
  MimeBodyPart p1 = new MimeBodyPart();
  p1.setText("This is part one of a test multipart e-mail."
    + "The second part is file as an attachment");
  // Create second part
  MimeBodyPart p2 = new MimeBodyPart();
  // Put a file in the second part
  FileDataSource fds = new FileDataSource(filename);
  p2.setDataHandler(new DataHandler(fds));
  p2.setFileName(fds.getName());
  // Create the Multipart. Add BodyParts to it.
  Multipart mp = new MimeMultipart();
  mp.addBodyPart(p1);
  mp.addBodyPart(p2);
  // Set Multipart as the message's content
  msg.setContent(mp);
 }
 // Set a single part html content.
 // Sending data of any type is similar.
 public static void setHTMLContent(Message msg) throws MessagingException {
  String html = "&#60;html&#62;&#60;head&#62;&#60;title&#62;" + msg.getSubject()
    + "&#60;/title&#62;&#60;/head&#62;&#60;body&#62;&#60;h1&#62;" + msg.getSubject()
    + "&#60;/h1&#62;&#60;p&#62;This is a test of sending an HTML e-mail"
    + " through Java.&#60;/body&#62;&#60;/html&#62;";
  // HTMLDataSource is an inner class
  msg.setDataHandler(new DataHandler(new HTMLDataSource(html)));
 }
 /*
  * Inner class to act as a JAF datasource to send HTML e-mail content
  */
 static class HTMLDataSource implements DataSource {
  private String html;
  public HTMLDataSource(String htmlString) {
   html = htmlString;
  }
  // Return html string in an InputStream.
  // A new stream must be returned each time.
  public InputStream getInputStream() throws IOException {
   if (html == null)
    throw new IOException("Null HTML");
   return new ByteArrayInputStream(html.getBytes());
  }
  public OutputStream getOutputStream() throws IOException {
   throw new IOException("This DataHandler cannot write HTML");
  }
  public String getContentType() {
   return "text/html";
  }
  public String getName() {
   return "JAF text/html dataSource to send e-mail only";
  }
 }
} // End of class</pre>
<p>This is the sample code for sending  email  of  type multipart, having attachments  and HTML content.</p>
<p>Compile and run the program after making necessary changes for email addresses of  To and From and Server Address , file path for attachment etc.</p>
<p>In next part i&#8217;ll provide the sample code for Fetching emails and Forwarding them to others.</p>
<p> </p>
<p>Keep Coding  &#8230;</p>
<p>Ashish</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Mail]]></title>
<link>http://malliktalksjava.in/2009/07/09/java-mail/</link>
<pubDate>Thu, 09 Jul 2009 13:47:00 +0000</pubDate>
<dc:creator>Mallik</dc:creator>
<guid>http://malliktalksjava.in/2009/07/09/java-mail/</guid>
<description><![CDATA[SEND MAIL EXAMPLE import java.util.Properties; import javax.mail.Message; import javax.mail.Session;]]></description>
<content:encoded><![CDATA[<p><strong>SEND MAIL EXAMPLE</strong></p>
<blockquote><p>import java.util.Properties;<br />
import javax.mail.Message;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeMessage;</p>
<p>public class TestMail {<br />
public static void main(String args[]) throws Exception {<br />
String host = &#8220;localhost&#8221;;<br />
String from = &#8220;nani@gmail.com&#8221;;<br />
String to = &#8220;nani@gmail.com&#8221;;<br />
String user = &#8220;mallik&#8221;;<br />
String password = &#8220;mallik&#8221;;<br />
String content = &#8220;Change your password.&#8221;;<br />
Properties properties = System.getProperties();<br />
properties.setProperty(&#8220;mail.smtp.host&#8221;, host);<br />
Session session =Session.getDefaultInstance(properties);<br />
MimeMessage message = new MimeMessage(session);<br />
message.setFrom(new InternetAddress(from));<br />
message.addRecipient(Message.RecipientType.TO, new           InternetAddress(to));<br />
message.setSubject(&#8220;Test Mail&#8221;);<br />
message.setText(content);</p>
<p>Transport.send(message);<br />
System.out.println(&#8220;Message Send Successfully&#8230;&#8221; +              content);</p>
<p>}<br />
}</p></blockquote>
<p><strong>READING MAIL EXAMPLE</strong></p>
<blockquote><p>import java.io.*;<br />
import java.util.*;<br />
import javax.mail.*;</p>
<p>public class ReadMail {<br />
public static void main(String args[]) throws Exception {<br />
String host = &#8220;localhost&#8221;;<br />
String user = &#8220;nani&#8221;;<br />
String password = &#8220;nani&#8221;;<br />
Properties properties = System.getProperties();<br />
Session session =                                             Session.getDefaultInstance (properties);<br />
Store store = session.getStore(&#8220;pop3&#8243;);<br />
store.connect(host, user, password);<br />
Folder folder = store.getFolder(&#8220;inbox&#8221;);<br />
folder.open(Folder.READ_ONLY);</p>
<p>Message[] message = folder.getMessages();</p>
<p>for (int i = 0; i &#60; message.length; i++) {<br />
System.out.println(&#8220;&#8212;&#8211; Message &#8221; + (i + 1) +     &#8221; &#8212;&#8212;&#8212;&#8212;&#8221;);<br />
System.out.println(&#8220;SentDate : &#8221; + message[i].        getSentDate());<br />
System.out.println(&#8220;From : &#8221; + message[i].        getFrom()[0]);<br />
System.out.println(&#8220;Subject : &#8221; + message[i].        getSubject());<br />
System.out.print(&#8220;Message : &#8220;);<br />
InputStream stream = message[i].                           getInputStream();<br />
while (stream.available() != 0) {<br />
System.out.print((char) stream.read());<br />
}<br />
}<br />
folder.close(true);<br />
store.close();<br />
}<br />
}</p></blockquote>
<p><strong>SENDIG MAIL WITH AN ATTACHMENT</strong></p>
<blockquote><p>import java.util.Properties;<br />
import javax.activation.DataHandler;<br />
import javax.activation.DataSource;<br />
import javax.activation.FileDataSource;<br />
import javax.mail.BodyPart;<br />
import javax.mail.Message;<br />
import javax.mail.Multipart;<br />
import javax.mail.SendFailedException;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeBodyPart;<br />
import javax.mail.internet.MimeMessage;<br />
import javax.mail.internet.MimeMultipart;</p>
<p>public class AttachExample {<br />
public static void main (String args[]) throws Exception {<br />
String host = &#8220;localhost&#8221;;<br />
String from = &#8220;nani@gmail.com&#8221;;<br />
String to[] =  new String[]{&#8220;nani@gmail.com&#8221;,&#8221;gopikanthk&#8221;};<br />
String filename = &#8220;testAttach.txt&#8221;;<br />
// Get system properties<br />
Properties props = System.getProperties();<br />
props.put(&#8220;mail.smtp.host&#8221;, host);<br />
Session session = Session.getInstance(props, null);<br />
System.out.println(session.getProperties());<br />
Message message = new MimeMessage(session);<br />
message.setFrom(new InternetAddress(from));</p>
<p>InternetAddress[] toAddress = new InternetAddress[to.length];<br />
for (int i = 0; i &#60; to.length; i++){<br />
toAddress[i] = new InternetAddress(to[i]);<br />
System.out.println(&#8220;to address are&#8212;&#8212;&#8211;&#8221;+toAddress[i]);<br />
}<br />
message.setRecipients(Message.RecipientType.TO, toAddress);<br />
String a=null;<br />
System.out.println(&#8220;recipent type to&#8212;-&#8221;);<br />
message.setSubject(&#8220;Hello JavaMail Attachment&#8221;);<br />
System.out.println(&#8220;After the subject&#8212;&#8212;&#8212;&#8221;);<br />
BodyPart messageBodyPart = new MimeBodyPart();<br />
messageBodyPart.setText(&#8220;Here&#8217;s the file&#8221;);<br />
System.out.println(&#8220;After the content of the message&#8212;-&#8221;);<br />
Multipart multipart = new MimeMultipart();</p>
<p>multipart.addBodyPart(messageBodyPart);<br />
messageBodyPart = new MimeBodyPart();</p>
<p>DataSource source = new FileDataSource(filename);</p>
<p>messageBodyPart.setDataHandler(new DataHandler(source));<br />
System.out.println(&#8220;After the data handler&#8212;-&#8221;);<br />
messageBodyPart.setFileName(filename);<br />
multipart.addBodyPart(messageBodyPart);<br />
message.setContent(multipart);<br />
try{<br />
System.out.println(&#8220;In try block&#8212;&#8212;-&#8221;);<br />
Transport.send(message);<br />
System.out.println(&#8220;messages sent successfully&#8230;&#8230;&#8230;&#8221;);<br />
}<br />
catch(SendFailedException sfe)<br />
{<br />
message.setRecipients(Message.RecipientType.TO,  sfe.getValidUnsentAddresses());<br />
Transport.send(message);</p>
<p>}<br />
}</p>
<p>}</p></blockquote>
]]></content:encoded>
</item>
<item>
<title><![CDATA[tugas numpuk...]]></title>
<link>http://eecchhoo.wordpress.com/2009/05/02/tugas-numpuk/</link>
<pubDate>Sat, 02 May 2009 01:30:55 +0000</pubDate>
<dc:creator>Eko Kurniawan Khannedy</dc:creator>
<guid>http://eecchhoo.wordpress.com/2009/05/02/tugas-numpuk/</guid>
<description><![CDATA[wew, lagi asik2nya nich&#8230;. banyak tugas, tugas proposal, laporan, sampe persentasi&#8230; sampe]]></description>
<content:encoded><![CDATA[wew, lagi asik2nya nich&#8230;. banyak tugas, tugas proposal, laporan, sampe persentasi&#8230; sampe]]></content:encoded>
</item>
<item>
<title><![CDATA[Mail Send With Attachments]]></title>
<link>http://ashwinrayaprolu.wordpress.com/2009/01/12/mail-send-with-attachments/</link>
<pubDate>Mon, 12 Jan 2009 12:39:35 +0000</pubDate>
<dc:creator>ashwinrayaprolu</dc:creator>
<guid>http://ashwinrayaprolu.wordpress.com/2009/01/12/mail-send-with-attachments/</guid>
<description><![CDATA[Sample Program To Send Mail from Java /** * */ package com.webaging.utils; import java.util.Iterator]]></description>
<content:encoded><![CDATA[<p>Sample Program To Send Mail from Java</p>
<p><code></p>
<p>/**<br />
 *<br />
 */<br />
package com.webaging.utils;</p>
<p>import java.util.Iterator;<br />
import java.util.List;<br />
import java.util.Properties;</p>
<p>import javax.activation.DataHandler;<br />
import javax.activation.DataSource;<br />
import javax.activation.FileDataSource;<br />
import javax.mail.Message;<br />
import javax.mail.MessagingException;<br />
import javax.mail.Multipart;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.AddressException;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeBodyPart;<br />
import javax.mail.internet.MimeMessage;<br />
import javax.mail.internet.MimeMultipart;</p>
<p>/**<br />
 * @author Ashwin<br />
 *<br />
 */<br />
public class MailSender {</p>
<p>	/**<br />
	 * @param from<br />
	 * @param to<br />
	 * @param subject<br />
	 * @param message<br />
	 * @throws Exception<br />
	 */<br />
	public static void sendMail(String host, String fromAddress,<br />
			List toAddresses, String subject, String messageContent,<br />
			String[] attachments) throws Exception {<br />
		// Create empty properties<br />
		try {<br />
			Properties props = System.getProperties();<br />
			props.put("mail.pop3.host", host);<br />
			Session session = Session.getInstance(props, null);</p>
<p>			MimeMessage message = new MimeMessage(session);<br />
			InternetAddress from = new InternetAddress(fromAddress);<br />
			message.setFrom(from);<br />
			message.setSubject(subject);</p>
<p>			for (Iterator it = toAddresses.iterator(); it.hasNext();) {<br />
				message.addRecipient(Message.RecipientType.TO,<br />
						new InternetAddress((String) it.next()));<br />
			}</p>
<p>			Multipart multipart = new MimeMultipart();<br />
			MimeBodyPart messageBodyPart = new MimeBodyPart();<br />
			messageBodyPart.setContent(messageContent + "</p>
<p>", "text/html");<br />
			multipart.addBodyPart(messageBodyPart);</p>
<p>			// add any file attachments to the message<br />
			addAtachments(attachments, multipart);</p>
<p>			message.setContent(multipart);<br />
			// Now Send the message<br />
			Transport.send(message);</p>
<p>		} catch (Exception e) {<br />
			throw e;<br />
		}</p>
<p>	}</p>
<p>	/**<br />
	 * @param attachments<br />
	 * @param multipart<br />
	 * @throws MessagingException<br />
	 * @throws AddressException<br />
	 */<br />
	protected static void addAtachments(String[] attachments,<br />
			Multipart multipart) throws MessagingException, AddressException {<br />
		for (int i = 0; i &#60;= attachments.length - 1; i++) {<br />
			String filename = attachments[i];<br />
			MimeBodyPart attachmentBodyPart = new MimeBodyPart();</p>
<p>			// use a JAF FileDataSource as it does MIME type detection<br />
			DataSource source = new FileDataSource(filename);<br />
			attachmentBodyPart.setDataHandler(new DataHandler(source));</p>
<p>			// assume that the filename you want to send is the same as the<br />
			// actual file name - could alter this to remove the file path<br />
			attachmentBodyPart.setFileName(filename);</p>
<p>			// add the attachment<br />
			multipart.addBodyPart(attachmentBodyPart);<br />
		}<br />
	}</p>
<p>}</p>
<p></code></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Read Mail Java]]></title>
<link>http://ashwinrayaprolu.wordpress.com/2009/01/12/read-mail-java/</link>
<pubDate>Mon, 12 Jan 2009 12:37:15 +0000</pubDate>
<dc:creator>ashwinrayaprolu</dc:creator>
<guid>http://ashwinrayaprolu.wordpress.com/2009/01/12/read-mail-java/</guid>
<description><![CDATA[Sample Program to Read Mail package com.ashwin; import java.io.IOException; import java.util.ArrayLi]]></description>
<content:encoded><![CDATA[<p>Sample Program to Read Mail</p>
<p><code></p>
<p>package com.ashwin;</p>
<p>import java.io.IOException;<br />
import java.util.ArrayList;<br />
import java.util.HashMap;<br />
import java.util.List;<br />
import java.util.Map;<br />
import java.util.Properties;</p>
<p>import javax.mail.Address;<br />
import javax.mail.Authenticator;<br />
import javax.mail.Folder;<br />
import javax.mail.Message;<br />
import javax.mail.MessagingException;<br />
import javax.mail.Multipart;<br />
import javax.mail.Part;<br />
import javax.mail.Session;<br />
import javax.mail.Store;<br />
import javax.mail.event.FolderListener;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeMessage;</p>
<p>public class MailReaderUtility {</p>
<p>	public static void main(String[] args) {<br />
		Authenticator auth = null;<br />
		Folder folder = null;<br />
		Store store = null;<br />
		String comment = "";<br />
		String subject = "";<br />
		String from = "";</p>
<p>		try {</p>
<p>			auth = new SMTPAuthenticator(args[0],args[1]);</p>
<p>			// Create empty properties<br />
			Properties props = System.getProperties();<br />
			props.put("mail.pop3.host", args[2]);<br />
			// get session<br />
			Session session = Session.getDefaultInstance(props, auth);<br />
			// Get the store<br />
			store = session.getStore("pop3");<br />
			store.connect();<br />
			// Get folder<br />
			FolderListener arg0;<br />
			// store.addFolderListener();</p>
<p>			// store.addFolderListener();<br />
			folder = store.getFolder("INBOX");<br />
			folder.open(Folder.READ_WRITE);<br />
			// Get directory\\<br />
			Message message[] = folder.getMessages();<br />
			for (int i = 0, n = message.length; i &#60; n; i++) {<br />
				Map dataStore = new HashMap();<br />
				Address[] addresses = message[i].getFrom();<br />
				InternetAddress address = (InternetAddress) addresses[0];<br />
				from = address.getAddress();<br />
				subject = message[i].getSubject();<br />
				dataStore.put("from", from);<br />
				dataStore.put("subject", subject);</p>
<p>				if (((MimeMessage) message[i]).getContent() instanceof String) {<br />
					// content is texText<br />
					// System.out.println(((MimeMessage)<br />
					// message[i]).getContent());<br />
					comment = ((MimeMessage) message[i]).getContent()<br />
							.toString();<br />
					dataStore.put("comment", comment);<br />
				} else if (((MimeMessage) message[i]).getContent() instanceof Multipart<br />
						&#124;&#124; ((MimeMessage) message[i]).getContent() instanceof Part) {<br />
					Multipart multiPartcnt = (Multipart) ((MimeMessage) message[i])<br />
							.getContent();</p>
<p>					Object content = message[i].getContent();<br />
					if (content instanceof Multipart) {<br />
						handleMultipart((Multipart) content, dataStore);<br />
					} else {<br />
						handlePart(message[i], dataStore);<br />
					}</p>
<p>					comment = multiPartcnt.getBodyPart(0).getContent()<br />
							.toString();<br />
					// recursively iterate over container's contents to<br />
					// retrieve<br />
					// attachments<br />
				} else if (((MimeMessage) message[i]).getContent() instanceof Message) {<br />
					// message content could be a message itself<br />
				}</p>
<p>				System.out.println("From: "+dataStore.get("from"));<br />
				System.out.println("Subject: "+dataStore.get("subject"));<br />
				String testComment = (String)dataStore.get("comment");<br />
				if(testComment.length() &#60; 15){<br />
					System.out.println("Data: "+testComment.substring(0, testComment.length()));<br />
				}else{<br />
					System.out.println("Data: "+testComment.substring(0, 14));<br />
				}<br />
				System.out.println("------------------------------------");<br />
			}<br />
		}catch(Exception e){<br />
			e.printStackTrace();<br />
		}</p>
<p>	}</p>
<p>	public static void handleMultipart(Multipart multipart,<br />
			Map dataStore) throws MessagingException,<br />
			IOException {<br />
		for (int i = 0, n = multipart.getCount(); i &#60; n; i++) {<br />
			handlePart(multipart.getBodyPart(i), dataStore);<br />
		}<br />
	}</p>
<p>	public static void handlePart(Part part, Map dataStore)<br />
			throws MessagingException, IOException {<br />
		String disposition = part.getDisposition();<br />
		String contentType = part.getContentType();<br />
		// System.out.println("In Handle Part : " + contentType);<br />
		if (disposition == null) { // When just body<br />
			// System.out.println("Null: " + contentType);<br />
			// Check if plain<br />
			if ((contentType.length() &#62;= 10)<br />
					&#38;&#38; (contentType.toLowerCase().substring(0, 10)<br />
							.equals("text/plain"))) {<br />
				// part.writeTo(System.out);<br />
				dataStore.put("comment", part.getContent().toString());<br />
			} else { // Don't think this will happen<br />
				// System.out.println("Other body: " + contentType);<br />
				dataStore.put("comment", part.getContent().toString());<br />
			}<br />
		} else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {<br />
			// System.out.println("Attachment: " + part.getFileName() + " : "+<br />
			// contentType);<br />
			List fileNames = (List) dataStore.get("attachment");<br />
			if (fileNames == null) {<br />
				fileNames = new ArrayList();<br />
			}<br />
			fileNames.add(part.getFileName());<br />
			dataStore.put("attachment", fileNames);<br />
			//saveFile(part.getFileName(), part.getInputStream());<br />
		} else if (disposition.equalsIgnoreCase(Part.INLINE)) {<br />
			// System.out.println("Inline: " + part.getFileName() + " : " +<br />
			// contentType);<br />
			//saveFile(part.getFileName(), part.getInputStream());<br />
		} else { // Should never happen<br />
			// System.out.println("Other: " + disposition);<br />
		}<br />
	}<br />
}</p>
<p></code></p>
<p>SMTP Authenticator</p>
<p><code><br />
/**<br />
 *<br />
 */<br />
package com.ashwin;</p>
<p>import javax.mail.Authenticator;<br />
import javax.mail.PasswordAuthentication;</p>
<p>/**<br />
 * @author ashwin<br />
 *<br />
 */<br />
public class SMTPAuthenticator extends Authenticator<br />
{<br />
	String masteruser = null;<br />
	String masterpswd = null;</p>
<p>	SMTPAuthenticator(String user, String password)<br />
	{<br />
		masteruser = user;<br />
		masterpswd = password;<br />
	}<br />
	public PasswordAuthentication getPasswordAuthentication()<br />
	{</p>
<p>		return new PasswordAuthentication(masteruser, masterpswd);<br />
	}<br />
}<br />
</code></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[JAVA - Send email From JAVA Application &amp; Command Line - Febootimail]]></title>
<link>http://robbamforth.wordpress.com/2008/10/31/java-send-email-from-java-application-command-line-febootimail/</link>
<pubDate>Fri, 31 Oct 2008 15:57:03 +0000</pubDate>
<dc:creator>Rob Bamforth</dc:creator>
<guid>http://robbamforth.wordpress.com/2008/10/31/java-send-email-from-java-application-command-line-febootimail/</guid>
<description><![CDATA[  Sending an email from a JAVA application. I&#8217;ve discovered another great tool this week]]></description>
<content:encoded><![CDATA[<p> </p>
<p>Sending an email from a JAVA application.</p>
<p>I&#8217;ve discovered another great tool this week &#8211; Febootimail.<br />
It allows you to send an email from the command line &#8211; meaning that you can send an email from any JAVA application running on a windows OS. Not just basic emails, but HTML email, attachments etc.</p>
<p> </p>
<p>STEP 1 Download &#38; Install febootimail.exe:</p>
<p>The Febootimail application can be downloaded from the following location -<br />
<a href="http://www.febooti.com/downloads/">http://www.febooti.com/downloads/</a><br />
and look for the setup / installer EXE.</p>
<p>Once downloaded run the setup process &#8211; the default setup location is <strong>C:\Program Files\febooti Command line email\</strong></p>
<p>When the install is complete navigate to the install directory and look for a file called <strong>febootimail.exe</strong>.<br />
This is the EXE that you will call from your JAVA application. If you only intend running your application on your local pc then this is fine. I run it from a server side application, so copied febootimail.exe to a server location accessible from all the clients running my JAVA app.</p>
<p> </p>
<p>STEP 2 Call Febootimail.exe From the Application:</p>
<p>The following is an extract from a simple class that will send an email.</p>
<p> </p>
<p> </p>
<blockquote>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;">try{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>String cmd;<br />
</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd = &#8220;</span><span style="font-size:small;color:#000000;font-family:Times New Roman;"> </span><span style="font-size:10pt;color:red;font-family:Verdana;">C:\Program Files\febooti Command line email\febootimail.exe&#8221;; // LINE1</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>   </span><span>       </span>cmd += &#8221; -SERVER mail.yourserver.net&#8221;;//LINE 2</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -FROM info@yourdomain.co.uk&#8221;; // LINE 3</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -TO toaddress@whoever.com&#8221; ; // LINE 4</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -MSG This is the body of the email address&#8221;; // LINE 5</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -HTML &#8220;; // LINE 6</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -SUBJ This Is The Subject&#8221;; // LINE 7</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -FROMNAME fromaddress@yourdomain.com&#8221;; // LINE 8</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>cmd += &#8221; -AUTH AUTO -USER username -PASS password &#8220;; // LINE 9<br />
</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>          </span>Process p = Runtime.getRuntime().exec(cmd); </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;">}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;">catch(Exception e){</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;"><span>            </span>e.printStackTrace();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:red;font-family:Verdana;">}</span></p>
</blockquote>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"> </p>
<p>Line 1: Points JAVA to febootimain.exe. Change the location depending on where you placed the exe.<br />
Line 2:  Supply your mail server name.<br />
Line 3: Supply a FROM address.<br />
Line 4: the recipient email address.<br />
Line 5: This is the message body. This could be HTML code.<br />
Line 6: Tells febootimail.exe to expect HTML in the message body.<br />
Line 7: Sets the subject.<br />
Line 8: sets the from name &#8211; this will abear as the sender alias.<br />
Line 9: The username and password for your mail server.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Sending Mail In Java]]></title>
<link>http://ashwinrayaprolu.wordpress.com/2008/08/29/sending-mail-in-java/</link>
<pubDate>Fri, 29 Aug 2008 17:29:18 +0000</pubDate>
<dc:creator>ashwinrayaprolu</dc:creator>
<guid>http://ashwinrayaprolu.wordpress.com/2008/08/29/sending-mail-in-java/</guid>
<description><![CDATA[Many people find it difficult sending mail from a program. This code shows how simple it is to send]]></description>
<content:encoded><![CDATA[<p>Many people find it difficult sending mail from a program. This code shows how simple it is to send a mail from java Program.</p>
<p>package com.webaging.utils;</p>
<p>import java.util.Properties;</p>
<p>import javax.activation.DataHandler;<br />
import javax.activation.DataSource;<br />
import javax.activation.FileDataSource;<br />
import javax.mail.BodyPart;<br />
import javax.mail.Message;<br />
import javax.mail.MessagingException;<br />
import javax.mail.Multipart;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.AddressException;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeBodyPart;<br />
import javax.mail.internet.MimeMessage;<br />
import javax.mail.internet.MimeMultipart;</p>
<p>/**<br />
* @author Ashwin<br />
*<br />
*/<br />
public class MailClient {</p>
<p>public void sendMail(String mailServer, String from, String to,<br />
String subject, String messageBody, String[] attachments)<br />
throws MessagingException, AddressException {<br />
// Setup mail server<br />
Properties props = System.getProperties();<br />
props.put(&#8220;mail.smtp.host&#8221;, mailServer);</p>
<p>// Get a mail session<br />
Session session = Session.getDefaultInstance(props, null);</p>
<p>// Define a new mail message<br />
Message message = new MimeMessage(session);<br />
message.setFrom(new InternetAddress(from));<br />
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));<br />
message.setSubject(subject);</p>
<p>// Create a message part to represent the body text<br />
BodyPart messageBodyPart = new MimeBodyPart();<br />
messageBodyPart.setText(messageBody);</p>
<p>// use a MimeMultipart as we need to handle the file attachments<br />
Multipart multipart = new MimeMultipart();</p>
<p>// add the message body to the mime message<br />
multipart.addBodyPart(messageBodyPart);</p>
<p>// add any file attachments to the message<br />
addAtachments(attachments, multipart);</p>
<p>// Put all message parts in the message<br />
message.setContent(multipart);</p>
<p>// Send the message<br />
Transport.send(message);</p>
<p>}</p>
<p>protected void addAtachments(String[] attachments, Multipart multipart)<br />
throws MessagingException, AddressException {<br />
for (int i = 0; i &#60;= attachments.length &#8211; 1; i++) {<br />
String filename = attachments[i];<br />
MimeBodyPart attachmentBodyPart = new MimeBodyPart();</p>
<p>// use a JAF FileDataSource as it does MIME type detection<br />
DataSource source = new FileDataSource(filename);<br />
attachmentBodyPart.setDataHandler(new DataHandler(source));</p>
<p>// assume that the filename you want to send is the same as the<br />
// actual file name &#8211; could alter this to remove the file path<br />
attachmentBodyPart.setFileName(filename);</p>
<p>// add the attachment<br />
multipart.addBodyPart(attachmentBodyPart);<br />
}<br />
}</p>
<p>public static void main(String[] args) {<br />
try {<br />
MailClient client = new MailClient();<br />
String server = &#8220;pop3.mydomain.com&#8221;;<br />
String from = &#8220;myname@mydomain.com&#8221;;<br />
String to = &#8220;someuser@somewhere.com&#8221;;<br />
String subject = &#8220;Test&#8221;;<br />
String message = &#8220;Testing&#8221;;<br />
String[] filenames = { &#8220;c:\\somefile.txt&#8221; };</p>
<p>client.sendMail(server, from, to, subject, message, filenames);<br />
} catch (Exception e) {<br />
e.printStackTrace(System.out);<br />
}</p>
<p>}<br />
}</p>
<p>Courtesy: <a class="aligncenter" title="Java Mail Example" href="http://www.osix.net/modules/article/?id=39" target="_blank">http://www.osix.net/modules/article/?id=39</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Unit testing email]]></title>
<link>http://twasink.net/2004/08/26/unit-testing-email/</link>
<pubDate>Thu, 26 Aug 2004 06:58:00 +0000</pubDate>
<dc:creator>Robert Watkins</dc:creator>
<guid>http://twasink.net/2004/08/26/unit-testing-email/</guid>
<description><![CDATA[The JavaMail API is a nice, simple, and effective API. But it&#8217;s got one problem: it&#8217;s a]]></description>
<content:encoded><![CDATA[The JavaMail API is a nice, simple, and effective API. But it&#8217;s got one problem: it&#8217;s a]]></content:encoded>
</item>

</channel>
</rss>
