aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending Mail in HTML for mat with Attachemnt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending Mail in HTML for mat with Attachemnt" Watch "Sending Mail in HTML for mat with Attachemnt" New topic
Author

Sending Mail in HTML for mat with Attachemnt

Raj kalaria
Ranch Hand

Joined: Sep 08, 2005
Posts: 72
Hi

I am writing a code to send a mail (its only in JAVA no JSP )
it has an attachment and few instructions

------------------********-----------------------------------------

The following task has arrived in your Documentum Inbox. Double-click the attached file to perform the task.


FromRaj
Sent:9/8/2005 9:49:19 AM
Docbase:vmrdev01
Priority:Medium

THe Instructions:kgggkgg
---------------------*****----------------------------------
Now I am able to send the attachment and the first line only that is
" The following task has arrived in your Documentum Inbox. Double-click the attached file to perform the task."

Now i want to send the remaining lines but in HTML format that is i want to used BOLD property.

---------------------- My code --------------------

// Get session
Session session1 = Session.getDefaultInstance(props, null);
// session1.setDebug(sessionDebug);
System.out.println("session is created ");


// Define message
Message msg = new MimeMessage(session1);
msg.setSentDate(new java.util.Date());
// Set the from address
msg.setFrom(new InternetAddress(from));
// Set the to address

InternetAddress[] address = {new InternetAddress(to)};
msg.addRecipients( Message.RecipientType.TO, address);
// Set the subject
msg.setSubject(document_name);
// Set the content
// changes msg.setText(task_perform);

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(task_perform);
// messageBodyPart.setText(alokmessage);
System.out.println(alokmessage);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(task_link);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(task_link);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
// msg.setContent(multipart,"html");
*******************************************************
msg.setContent(multipart);

********************************************************
System.out.println("message is created ");
// Send message
try
{
Transport.send(msg);
System.out.println("message sent ");
sent = true;
}
catch (SendFailedException e )
{
System.out.println ("the problem is " + e);
}
catch (MessagingException e )
{
System.out.println("Could not find the attachemnt " + e);
}

if (sent)
{
System.out.println("the message has been sent");
File myFile = new File (task_link);
boolean retval = myFile.delete();
if (retval)
{
System.out.println("The File was successfully Deleted");
}
else
{
System.out.println("The File was not successfully Deleted");
}
}

----------------------************------------------------------

now if i change the line
msg.setContent(multipart,"html")

it will give me error
" [B]Could not find the attachment javaxmailinternet parse Excpeption
Raj kalaria
Ranch Hand

Joined: Sep 08, 2005
Posts: 72
sorry the subject line is

Sending Mail in HTML with Attachemnt and some content
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Mail in HTML for mat with Attachemnt
 
Similar Threads
java mail attachment notification
Attachment in email not working in server
How To Send Multiple Attachments In An Email
Send jsp page in mail as attachment
javamail API question: How to send content type in message body when using multiparts