java - Error in triggering mails through simple program -
hi trying trigger mail through program getting error below. can possible can trigger mail dam.da@abc.com using host 192.168.195.68 , default port 25 default instance dont have create session , pass passswords , different username. please me on this.
![import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class sendemail { public static void main(string \[\] args) { // recipient's email id needs mentioned. string = "dam.da@abc.com"; // sender's email id needs mentioned string = "dam.da@abc.com"; // assuming sending email localhost string host = "192.168.195.68"; // system properties properties properties = system.getproperties(); // setup mail server properties.setproperty("mail.smtp.host", host); // default session object. session session = session.getdefaultinstance(properties); try{ // create default mimemessage object. mimemessage message = new mimemessage(session); // set from: header field of header. message.setfrom(new internetaddress(from)); // set to: header field of header. message.addrecipient(message.recipienttype.to, new internetaddress(to)); // set subject: header field message.setsubject("this subject line!"); // set actual message message.settext("this actual message"); // send message transport.send(message); system.out.println("sent message successfully...."); }catch (messagingexception mex) { mex.printstacktrace(); } } }
Comments
Post a Comment