javamail - In java program removing the code of attachments and simply sending the mails through java mail -


i have develop program in java using java mail api in have send mail rite have coded java program in fashion in can have multiple recipients in section of mail , in multiple recipients in cc section also

earlier have coded below java program in attachments send rite have decided remove functionality of sending attachments attachements not sent simple mail send clients

so below method in parameters passes , please advise below implemtation of method correct , want remove attachment code aatachments not send , simple mails without attachment need sent please advise how can remove piece of code mail

public static void sendemail(string mailto[], string mailcc[], string from, string subject, string text, string smtphost , string mailsmtpport) throws exception, documentexception, ioexception {         try {             properties properties = new properties();             properties.put("mail.smtp.host", smtphost);             properties.put("mailsmtpport", mailsmtpport);              //obtaining session             session emailsession = session.getdefaultinstance(properties);              //enable debuging              emailsession.setdebug(true);              message emailmessage = new mimemessage(emailsession);              internetaddress[] addressto = new internetaddress[mailto.length];             (int = 0; < mailto.length; i++) {                 addressto[i] = new internetaddress(mailto[i]);             }             emailmessage.setrecipients(recipienttype.to, addressto);              internetaddress[] addresscc = new internetaddress[mailcc.length];             (int = 0; < mailcc.length; i++) {                 addresscc[i] = new internetaddress(mailcc[i]);             }             emailmessage.setrecipients(recipienttype.cc, addresscc);               emailmessage.setfrom(new internetaddress(from));              emailmessage.setsubject(subject);                // create message part   ****** part required attachemts no more being sent ***              bodypart messagebodypart = new mimebodypart();              messagebodypart.setcontent(text, "text/html");               //    messagebodypart.settext(text);               // create multipart message               multipart multipart = new mimemultipart();               multipart.addbodypart(messagebodypart);                //  attachment part                  mimebodypart attachpart = new mimebodypart();                  //string filename = "c:\\ap.xls";                      //datasource source = new filedatasource(filename);                  //attachpart.setdatahandler(new datahandler(source));                  //attachpart.setfilename(filename);                   multipart.addbodypart(attachpart);                 // send complete message parts                  emailmessage.setcontent(multipart);             transport.send(emailmessage);         }    catch (addressexception e) {             e.printstacktrace();         } catch (messagingexception e) {             e.printstacktrace();         }      }  

change declaration to:

mimemessage emailmessage = new mimemessage(emailsession); 

between setsubject , send, replace code with:

emailmessage.settext(text, null, "html"); 

replace session.getdefaultinstance session.getinstance.

remove "mailsmtpport" property since nothing. (did make up, or did copy else?)

simple enough?

did know there's lots of sample code available, , more information in javamail faq?


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -