String testHTMLContent = testhtml+productlogo;
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(usern));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
message.setRecipients(Message.RecipientType.CC,InternetAddress.parse(ccaddr));
message.setSubject(sub);
//message.setText(body);
// setDebugMsg("Attempting to send...");
Transport transport = session.getTransport("smtps");
MimeMultipart mimeMultipart = new MimeMultipart();
MimeBodyPart msgContent = new MimeBodyPart();
msgContent.setContent(testcontent, "text/plain");
mimeMultipart.addBodyPart(msgContent);
MimeBodyPart query = new MimeBodyPart();
query.setHeader("Content-Type", "text/plain");
query.setContent(queryString, "text/plain");
mimeMultipart.addBodyPart(query);
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setHeader("Content-Type", "text/html");
htmlPart.setContent(testHTMLContent,"text/html");
mimeMultipart.addBodyPart(htmlPart);
attachedfile="filepath/attach.docx";
if(attachedfile.length()!=0){
MimeBodyPart attachmentContent = new MimeBodyPart();
DataSource source = new FileDataSource(attachedfile);
attachmentContent.setDataHandler(new DataHandler(source));
attachmentContent.setFileName(attachedfile);
mimeMultipart.addBodyPart(attachmentContent);
}
message.setContent(mimeMultipart);
transport.connect("smtp.gmail.com", 465, usern, pass);
Transport.send(message);
transport.close();
The above code is sending the only the resolution as content and the second text 'query' as attachment(.txt) and html content as .htm attachment. Please coorect the code..Thanks..
Hemanth.Satkuri 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.