<?xml version="1.0" encoding="UTF-8"?><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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>email &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Wed, 06 Apr 2011 10:00:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>A simple program to send email in JAVA</title>
		<link>https://www.jitendrazaa.com/blog/java/a-simple-program-to-send-email-in-java/</link>
					<comments>https://www.jitendrazaa.com/blog/java/a-simple-program-to-send-email-in-java/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 06 Apr 2011 10:00:31 +0000</pubDate>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[SMTP]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1917</guid>

					<description><![CDATA[A Simple SMTP Email Program in JAVA]]></description>
										<content:encoded><![CDATA[<p>We will see a very simple program to send the email in JAVA using <a title="JAVA Email API" href="http://www.oracle.com/technetwork/java/javamail/index.html" target="_blank">JAVAMail API</a>. Please download all the jar files and include in the library.</p>
<p>Code to send email :<span id="more-1917"></span></p>
<pre class="brush: java; title: ; notranslate">

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;

public class SendMailUsingAuthentication
{

  private static final String SMTP_HOST_NAME = &quot;SMTP_HOST_NAME&quot;;
  private static final String SMTP_PORT = &quot;465&quot;;

  private static final String SMTP_AUTH_USER = &quot;SENDER_EMAIL&quot;;
  private static final String SMTP_AUTH_PWD  = &quot;SENDER_PASS&quot;;

  private static final String emailMsgTxt      = &quot;-----------Hello------------------ &quot;;
  private static final String emailSubjectTxt  = &quot;Test Mail from JAVA&quot;;
	private static final String emailFromAddress = &quot;FROM_EMAIL&quot;;

  // Add List of Email address to who email needs to be sent to
	private static final String&#x5B;] emailList = { &quot;TO_EMAIL_USER1&quot;,&quot;TO_EMAIL_USER2&quot; };

  public static void main(String args&#x5B;]) throws Exception
  {
    SendMailUsingAuthentication mailSender = new SendMailUsingAuthentication();
	mailSender.postMail(emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    System.out.println(&quot;Sucessfully Sent mail to All Users&quot;);
  }

  public void postMail( String recipients&#x5B; ], String subject,
                            String message , String from) throws MessagingException
  {
    boolean debug = false;
            //Set the host smtp address
	Properties props = new Properties();
	props.put(&quot;mail.smtp.host&quot;, SMTP_HOST_NAME);
	props.put(&quot;mail.smtp.socketFactory.port&quot;, SMTP_PORT);
            //IF SSL required by Host
	props.put(&quot;mail.smtp.socketFactory.class&quot; , &quot;javax.net.ssl.SSLSocketFactory&quot;);
	props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
	props.put(&quot;mail.debug&quot;, &quot;true&quot;);
	props.put(&quot;mail.smtp.port&quot;, SMTP_PORT);

            //Authenticate the Username and password for the SMTP
	Authenticator auth = new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);

    Session session = Session.getDefaultInstance(props, auth);

    session.setDebug(debug);

    // create a message
    Message msg = new MimeMessage(session);

    // set the from and to address
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress&#x5B;] addressTo = new InternetAddress&#x5B;recipients.length];
    for (int i = 0; i &lt; recipients.length; i++)
    {
        addressTo&#x5B;i] = new InternetAddress(recipients&#x5B;i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, &quot;text/plain&quot;);
    System.out.println(&quot;Sending Email...........&quot;);
    Transport.send(msg);

    System.out.println(&quot;Email Sent.........&quot;);

 }

}
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/a-simple-program-to-send-email-in-java/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1917</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-04-17 13:35:21 by W3 Total Cache
-->