java mail send mail code problem
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shriram_virkar
Posted On:   Wednesday, November 26, 2003 10:44 PM

in post mail method if i want to change mailsmtphost(mail server) when i reuse this method but it's not get change can any one guide me for same public void postMail( String recipients, String subject, String message, String from,String mailserver) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", mailserver); System.out.println(mailserver); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); // create a message Mess   More>>

in post mail method if i want to change mailsmtphost(mail server) when i reuse this method but it's not get change can any one guide me for same


public void postMail( String recipients, String subject, String message, String from,String mailserver) throws MessagingException

{
boolean debug = false;

//Set the host smtp address

Properties props = new Properties();

props.put("mail.smtp.host", mailserver);

System.out.println(mailserver);


// create some properties and get the default Session

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

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 addressTo = new InternetAddress(recipients);

msg.setRecipient(Message.RecipientType.TO, addressTo);

// Optional : You can also set your custom headers in the
Email if you Want

msg.addHeader("ServerAdmin", "myHeaderValue");

// Setting the Subject and Content Type

msg.setSubject(subject);

msg.setContent(message, "text/plain");

Transport.send(msg);

}

   <<Less

Re: java mail send mail code problem

Posted By:   Hannes_Prokop  
Posted On:   Thursday, December 4, 2003 02:47 AM

insted of your lines:



Properties props = new Properties();
props.put("mail.smtp.host", mailserver);


try these:



Properties props = System.getProperties();
props.put("mail.smtp.host",mailserver);
About | Sitemap | Contact