Issue in sending email to a group email using java mail -
as subject self explanatory - facing issue in sending email group email using java mail.
i have gone through through several blogs & articles of no & not have precise answer or hangs in middle.
can please help. here mail class you. mail going have link ftp location & text file attachment.
to separate issue tried send simple mail group didn't either.
i tried find answers in places java-forums.org & stack overflow found no luck.
i appreciate quality time & in providing insight issue.
to explain issue better-
my automation framework when completes execution of test cases, sends mail me link execution report & log file attachment. audience report has expanded & need send mail group email address.
when set email (to group.email@company.com) none of users in group receives mail. if send email email address or else email address works.
i no logs or error & not able understand issue correctly.
an insight experts in understanding issue.
thanks in advance. akshat
import java.util.arraylist; import java.util.properties; import javax.activation.datahandler; import javax.activation.datasource; import javax.activation.filedatasource; import javax.mail.bodypart; import javax.mail.message; import javax.mail.message.recipienttype; import javax.mail.multipart; import javax.mail.session; import javax.mail.transport; import javax.mail.internet.internetaddress; import javax.mail.internet.mimebodypart; import javax.mail.internet.mimemessage; import javax.mail.internet.mimemultipart; public class reportmail { private mimemessage message = null; private session emailsession = null; private mimebodypart textpart = null; private arraylist<mimebodypart> attachmentarray = null; public void sendmailer(string mailtoid, string string, string mailserver1, int mailport, string mailadmin) { properties mailproperties = null; mailproperties = new properties(); string adminemailid = mailadmin; string mailserver = mailserver1; mailproperties.put("mail.transport.protocol", "smtp"); //mailproperties.put("mail.smtp.auth", "true"); mailproperties.put("mail.smtp.host", mailserver); mailproperties.put("mail.from", adminemailid); mailproperties.put("mail.smtp.port", mailport); mailproperties.put("mail.to", mailtoid); try { emailsession = session.getinstance(mailproperties); emailsession.setdebug(false); message = new mimemessage(emailsession); textpart = new mimebodypart(); attachmentarray = new arraylist<mimebodypart>(2); message.addrecipients(recipienttype.to, mailtoid); message.setsubject(string); message.setfrom(new internetaddress(adminemailid)); setcontent("<a href=\"file://tambe3/report/emailable-report.html\" target=\"_blank\">pcm automation report</a>"); //setcontent("test123"); sendemail(); } catch (exception e) { e.printstacktrace(); } } public void setcontent(string content) { try { textpart.setcontent(content, "text/html"); } catch (exception e) { e.printstacktrace(); } } public boolean sendemail() throws exception { try { multipart mp = new mimemultipart(); mp.addbodypart(textpart); (int = 0; < attachmentarray.size(); i++) mp.addbodypart(attachmentarray.get(i)); /******************** * */ // part 2 attachment bodypart messagebodypart = new mimebodypart(); messagebodypart = new mimebodypart(); messagebodypart.settext("below link test automation report link & attached log file. pfa."); //mp.addbodypart(messagebodypart); string filename = "logfile.log"; //c:\workspacepcmsanity\pcmsanity\logfile.log datasource source = new filedatasource(filename); messagebodypart.setdatahandler(new datahandler(source)); messagebodypart.setfilename(filename); mp.addbodypart(messagebodypart); /** * */ message.setcontent(mp); transport transport = emailsession.gettransport(); transport.connect(); transport.sendmessage(message, message.getrecipients(message.recipienttype.to)); transport.close(); } catch (exception e) { e.printstacktrace(); throw e; } return true; } }
java doesn't know whether email address single user or group. issue smtp server.
Comments
Post a Comment