Breaking News
Home / Java / Java Snippets / How to send email for GoDaddy using Java?

How to send email for GoDaddy using Java?

  1. package com.infuze.server.util;
  2.  
  3. import java.util.List;
  4. import java.util.Properties;
  5.  
  6. import javax.mail.Message;
  7. import javax.mail.Session;
  8. import javax.mail.Transport;
  9. import javax.mail.internet.InternetAddress;
  10. import javax.mail.internet.MimeMessage;
  11.  
  12. import com.livrona.comono.logger.Logger;
  13. import com.livrona.comono.logger.LoggerFactory;
  14.  
  15. public class EmailHelper {
  16.  
  17. private static final Logger log = LoggerFactory.createLogger(EmailHelper.class);
  18.        
  19.         public static void sendMailViaGodaddy(String from, String password,List<String> to,String subject,String text ) {
  20.         try {
  21.           Properties props = System.getProperties();
  22.           props.setProperty("mail.transport.protocol", "smtp");
  23.           props.setProperty("mail.host", "smtpout.secureserver.net");
  24.                        
  25.  
  26.          props.put("mail.smtp.auth", "true");
  27.          props.setProperty("mail.user", from);
  28.          props.setProperty("mail.password", password);
  29.  
  30.         Session mailSession = Session.getDefaultInstance(props, null);
  31.         // mailSession.setDebug(true);
  32.         Transport transport = mailSession.getTransport("smtp");
  33.         MimeMessage message = new MimeMessage(mailSession);
  34.         message.setSentDate(new java.util.Date());
  35.         message.setSubject(subject);
  36.         message.setFrom(new InternetAddress(from));
  37.         for (int i=0;i < to.size();i++)
  38.         {
  39.                                          
  40.          message.addRecipient(Message.RecipientType.TO, new  
  41.           InternetAddress(to.get(i)));
  42.         }
  43.                
  44.         message.setText(text);
  45.  
  46.                         transport.connect("smtpout.secureserver.net",from,password);
  47.         transport.sendMessage(message,
  48.          message.getRecipients(Message.RecipientType.TO));
  49.         transport.close();
  50.                        
  51.          log.debug("Email via go daddy sent");
  52.         } catch (Exception e) {
  53.           log.error("Failed to send Email : " + e.getMessage(), e);
  54.         }
  55.    }
  56. }
[pb_builder]

Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Advertisment ad adsense adlogger