Wednesday, February 24, 2016

Mail Sending procedure using struts2

1. If we want to send mail from my project then we need to less secure my gmail account. For this
purpose we need to go below links and  make this option enabled.
https://www.google.com/settings/security/lesssecureapps


Access for less secure apps  Enabled
If this was you
You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.


2. Struts.xml:
<!-- SMTP configuration -->
<param name="host">smtp.gmail.com</param>
<param name="port">465</param>
<param name="userName">mohona.ict.mbstu@gmail.com</param>  
<param name="password">makhondim77$#@!</param>
<!-- End of SMTP configuration -->


3. EmaiUtility.java:
Properties props = new Properties();
props.put("mail.smtp.user", userName);
props.put("mail.smtp.password", password);
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.debug", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.EnableSSL.enable", "true");
props.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
Here we need to use the port number as 465.
4. Links:
http://www.codejava.net/frameworks/struts/send-e-mail-with-attachments-in-struts2?showall=&start=4
5. http://www.codejava.net/attachments/article/221/Struts2EmailApp.zip


6. Error: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.


If we use password as like makhondim77(*& in xml file which contains & sign then we have to follow the following rules.


Common in xml how to escape the errors:
  1. ampersand (&) is escaped to &amp;
  2. double quotes (") are escaped to &quot;
  3. single quotes (') are escaped to &apos;
  4. less than (<) is escaped to . &lt;

No comments:

Post a Comment