Public final class Emails {
/** the Java Mail sender. */
private static Javamailsender Javamailsender;
/**
* Send.
*
* @param emaildata
* The email data
*/
public static void Send (Emailconfig.emaildata emaildata) {
Emailorsmslogentity emailorsmslogentity = new emailorsmslogentity ();
Emailorsmslogentity.setmessagetype (Messagetype.email);
Emailorsmslogentity.revodeip ();
try {
Javamailsender Javamailsender = Maildefaultsender ();
MimeMessage message = Javamailsender.createmimemessage ();
Mimemessagehelper messagehelper = new Mimemessagehelper (message,
True, constants.default_encoding);
Messagehelper.setfrom (Emaildata.getfrom ());
Emailorsmslogentity.setfrom (Emaildata.getfrom ());
Messagehelper.setto (Emaildata.to ());
Emailorsmslogentity.setto (Stringutils.join (Emaildata.to (), ","));
Messagehelper.setsubject (Emaildata.gettitle ());
Emailorsmslogentity.setsubject (Emaildata.gettitle ());
Messagehelper.settext (Emaildata.getcontent (), true);
Emailorsmslogentity.settext (Emaildata.getcontent ());
collection<file> files = emaildata.getattachment ();
if (Files! = null) {
list<string> fileNames = Lists.newarraylist ();
for (File file:files) {
Messagehelper.addattachment (File.getname (), file);
Filenames.add (File.getname ());
}
Emailorsmslogentity.addfeatures (Emailorsmslogentity.filetag,
Stringutils.join (FileNames, ","));
}
Javamailsender.send (message);
Emailorsmslogentity.setsuccess (TRUE);
} catch (Exception e) {
E.printstacktrace ();
Emailorsmslogentity.setsuccess (FALSE);
Emailorsmslogentity.setfailure (Throwables.getstacktraceasstring (e));
}
Emailorsmslogentity.createorupdate ();
}
/**
* AYSN send.
*
* @param emaildata
* The email data
*/
public static void Aysnsend (final emailconfig.emaildata emaildata) {
Swingutilities.invokelater (New Runnable () {
@Override
public void Run () {
Send (Emaildata);
}
});
}
/**
* Mail default sender.
*
* @return the Java Mail Sender
*/
public static Javamailsender Maildefaultsender () {
Return MailSender (Sysconfigentity.config ());
}
/**
* Mail sender.
*
* @param config
* the config
* @return the Java Mail sender
*/
Private Static Javamailsender MailSender (emailconfig config) {
Javamailsender Javamailsender = MailSender ();
if (javamailsender instanceof javamailsenderimpl && config! = null) {
Javamailsenderimpl Impl = (javamailsende Rimpl) Javamailsender;
if (config.getmailhost () = null)
Impl.sethost (Config.getmailhost ());
if (config.getmailpost () = null)
Impl.setport (Config.getmailpost ());
if (config.getmailusername () = null)
Impl.setusername (Config.getmailusername ());
if (Config.getmailpassword () = null)
Impl.setpassword (Cryptoutils.aesdecryptfromhex (
Config.getmailpassword (), Keyconstants.mailpassword));
}
return javamailsender;
}
/**
* Mail sender.
*
* @return the Java Mail Sender
*/
private static Javamailsender MailSender () {
if (Javamailsender! = null)
return javamailsender;
Synchronized (Emails.class) {
Javamailsender = Utils.Container.getBean (Javamailsender.class);
}
return javamailsender;
}
}
JavaMail sending mail through SMTP in spring