6 Replies - 281 Views - Last Post: 14 October 2012 - 02:22 PM Rate Topic: -----

#1 ibnmvungi  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 20-April 12

sendig mail to multiple

Posted 14 October 2012 - 12:35 PM

hogh guys. I have this program to send email. But when sending to hotmail account. The massage is not sent.

need help here please.

here is my code.


class Mail{

String d_email = "fghj@gmail.com",
d_password = "",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "adcf@live.com",
m_subject = "subject",
m_text = "this is just a test mail";

public Mail(String from,String to,String subject,String message, String filename,String attach_name) {
    d_email=from;
    m_to=to;
    m_subject=subject;
    m_text=message;
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

SecurityManager security = System.getSecurityManager();

try {
javax.mail.Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);

MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(m_to));

//attach file
/*
MimeBodyPart messagepart=new MimeBodyPart();
messagepart.setText(m_text);
Multipart multipart=new MimeMultipart();
         multipart.addBodyPart(messagepart);
     messagepart= new MimeBodyPart();
     javax.activation.DataSource source=new FileDataSource(filename);
     messagepart.setDataHandler(new DataHandler(source));
     messagepart.setFileName(attach_name);
     multipart.addBodyPart(messagepart);
     messagepart.setContent(multipart);
 * 
 */
//end of attach file
Transport.send(msg);

                        JOptionPane.showMessageDialog(null, "Message Sent");

} catch (Exception mex) {
         JOptionPane.showMessageDialog(null, "Sending message failed. Check your internet connection");

}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
       
        @Override
public javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(d_email, d_password);
}
}


}






Is This A Good Question/Topic? 0
  • +

Replies To: sendig mail to multiple

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2816
  • View blog
  • Posts: 11,924
  • Joined: 20-September 08

Re: sendig mail to multiple

Posted 14 October 2012 - 01:04 PM

Can't see offhand what's wrong with your code but i know this works

http://technojeeves....oogle-with-java

You just need to add more recipients as needed
Was This Post Helpful? 0
  • +
  • -

#3 ibnmvungi  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 20-April 12

Re: sendig mail to multiple

Posted 14 October 2012 - 01:33 PM

HALLO THERE WHEN SENDING AN EMAIL TO AHOT MAIL ACCOUNT THE EMAIL IS NOT DELIVERED.PLEASE HELP HERE

THIS IS THE CODE.


class Mail{

String d_email = "abcd@gmail.com",
d_password = "",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "efg@live.com",
m_subject = "subject",
m_text = "this is just a test mail";

public Mail(String from,String to,String subject,String message, String filename,String attach_name) {
    d_email=from;
    m_to=to;
    m_subject=subject;
    m_text=message;
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

SecurityManager security = System.getSecurityManager();

try {
javax.mail.Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);

MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(m_to));

//attach file
/*
MimeBodyPart messagepart=new MimeBodyPart();
messagepart.setText(m_text);
Multipart multipart=new MimeMultipart();
         multipart.addBodyPart(messagepart);
     messagepart= new MimeBodyPart();
     javax.activation.DataSource source=new FileDataSource(filename);
     messagepart.setDataHandler(new DataHandler(source));
     messagepart.setFileName(attach_name);
     multipart.addBodyPart(messagepart);
     messagepart.setContent(multipart);
 * 
 */
//end of attach file
Transport.send(msg);

                        JOptionPane.showMessageDialog(null, "Message Sent");

} catch (Exception mex) {
         JOptionPane.showMessageDialog(null, "Sending message failed. Check your internet connection");

}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
       
        @Override
public javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(d_email, d_password);
}
}

}




Was This Post Helpful? 0
  • +
  • -

#4 ibnmvungi  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 50
  • Joined: 20-April 12

Re: sendig mail to multiple

Posted 14 October 2012 - 01:40 PM

hallo there guys.Is there a tutorial on how to send sms to multiple recipitients.

Please help here
Was This Post Helpful? -1
  • +
  • -

#5 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: sendig mail to multiple

Posted 14 October 2012 - 02:03 PM

Remove all your socketFactory stuff, not required. Then your minimum should include
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.live.com");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");


If your server isnt running on port 25, you will need to add
props.put("mail.smtp.port", "587");


You can also look into using the Transport class. There are lots of examples like yours, and using the transport class online Example
Was This Post Helpful? 0
  • +
  • -

#6 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: sendig mail to multiple

Posted 14 October 2012 - 02:04 PM

And you cant use the search feature yourself because???
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10786
  • View blog
  • Posts: 40,164
  • Joined: 27-December 08

Re: sendig mail to multiple

Posted 14 October 2012 - 02:22 PM

Duplicate threads merged. Please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1