Home Discussion Discuss: Send multipart mail using java mail

  • question? send an email with an imageRaul perez September 13, 2013 at 7:20 PM

    Hi, sorry I have a question ... I'm trying to send an email with an image, meaning through JavaMail, I have installed the JDK 6.9 Here the code: try { Session session = null; Properties props = new Properties(); this.para=mail; props.setProperty("mail.smtp.host", this.servidor); props.setProperty("mail.smtp.port", this.puerto); props.setProperty("mail.smtp.starttls.enable", "true"); if (this.ssl){ props.put("mail.smtp.socketFactory.port", this.puerto); props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); } if( this.usuario != null && this.password != null && ! this.usuario.equals("") && ! this.password.equals("")){ props.put("mail.smtp.auth", "true"); props.put("mail.smtp.user", this.usuario ); session = Session.getInstance(props,new Authenticator(){ @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(USU ,PASS); } }); }else{ session = Session.getInstance(props, null); } MimeMultipart multiParte = new MimeMultipart(); BodyPart messageBodyPart = null; messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent("<html><h1>Hola Mundo</h1> <img src='cid:tdc_picture'></html>", "text/html"); multiParte.addBodyPart(messageBodyPart); /*EVERYTHING IS OK WITHOUT THIS, AND YES MAIL IS SENT messageBodyPart = new MimeBodyPart(); DataSource fds = new FileDataSource("C:\\minion.jpg"); messageBodyPart.setDataHandler(new DataHandler(fds)); messageBodyPart.setHeader("Content-ID","<tdc_picture>"); multiParte.addBodyPart(messageBodyPart); */ System.out.println("Todo correcto 0..."); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(this.usuario)); message.setSubject(this.asunto); message.setContent(multiParte); message.setSentDate(new Date()); // Obtener multiples correos destinatarios if (!this.para.equals("")){ String[] arr = this.para.split(";"); for (int i = 0; i < arr.length; i++) { if (!arr[i].trim().equals("")){ message.addRecipient(Message.RecipientType.TO,new InternetAddress(arr[i])); } } } System.out.println("Todo correcto 1..."); // Enviar correo Transport t = session.getTransport("smtp"); t.connect(this.servidor,this.usuario,this.password); t.sendMessage(message, message.getAllRecipients()); t.close(); System.out.println("MAIL SENT"); //Uncommenting CODE WHERE IS THE PICTURE, MAKE THE FOLLOWING ERROR: com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676) //AND ALSO MAKE ME AN ERROR IN THIS LINE t.sendMessage(message, message.getAllRecipients()); CAN ANYONE HELP ME? THANKS

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
General

Send multipart mail using java mail
Send multipart mail using java mail       This Example shows you how to send multipart mail using java mail. Multipart is like a container that holds one or more body 

JSP Interview Questions

mail
mail  how to send mail using jsp   Please visit the following links: JSP Send Mail Java Mail Tutorials 

JavaMail Questions

mail
mail  I wrote a program to send mail using smtp. But there is an error message " could not connect to smtp.gmail.com port 465. what is the problem how can i solve it ...   Please visit the following link: Java Mail API 

Java Mail

Read Multipart mail using Java Mail
Read Multipart mail using Java Mail   ... message using javamail api. When we read a multipart mail firstly create... the Java Mail api to accomplish your task.Using the Multipart ClassFollowing code 

JavaMail Questions

JAVA MAIL - JavaMail
cannot be applied to multipart... how to get my mail attachments in my application using JAVA MAIL API.  Hi Friend, Please explain us what code...JAVA MAIL  Hi! I am doing project called "E-mail Client 

Java Mail

Introduction of Java Mail
; Send multipart mail using java mail This Example shows you how to send multipart mail using java mail. Multipart is like a container... the message.   Read Multipart mail using Java Mail 

JavaMail Questions

java mail
message.setContent(multipart); // Send the message Transport.send(message...(MailClient.java:90) help me clear this error..send suggestions to mail mail...: Java Mail Thanks 

Java Beginners

send mail using smtp in java
send mail using smtp in java  How to send mail using smtp in java?   Sending mail in JSP - SMTP 

JavaMail Questions

java mail programs
java mail programs  I got some codes from this about sending mail,forwarding mail,multipart mail etc..and I compiled and executed it,but it did... have to make a web application which helps to send mail,plz give me a solution 

Java Beginners

Java Mail API Tutorial
Java Mail API Tutorial  I have to write programs using the Java Mail API. I want to learn the Java Mail API. Let's know the urls to learn Java Mail... Mail API. The Java Mail API allows you to send, read emails from Java program 

Java Beginners

java mail - Java Beginners
java mail  how to send mail using with out Authentication?????????/ using gmail server 

JavaMail Questions

Java Mail - JavaMail
Java Mail  how to email using Java mail or automatic generated mail???  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks 

JavaMail Questions

java mail error - JavaMail
java mail error  how to rceive emails using java mail api  Hi Friend, We can use Java Mail APIs to send and receive mails in Java.... Please visit the following link to know more about use of Java Mail API. http 

JavaMail Questions

java mail send using setText()
java mail send using setText()  Hai , Am newly mail send portion...); Here am using set Text() method to send mail content in html format. if i use... in java file . but if i use set Content() method, mail content is display html 

Java Beginners

java mail - Java Beginners
java mail  how to send a mail without authentication one domain....  Hi, You have to use the Java mail api. You need to use the SMTP... is tutorials on Java Mail API: http://www.roseindia.net/javamail/index.shtml http 

JavaMail Questions

Java Mail exception - JavaMail
Java Mail exception  Hi! I am developing E-mail Client (GMAIL) program using JSP technology. Till now i dont have any problem. From last 3 days while i am connecting to the Gmail, I am getting the following exception... Whats 

WebSevices Questions

How to read yahoo mail using java mail api - WebSevices
How to read yahoo mail using java mail api  Hi there .... i wanted to know how to read mail from yahoo using pure java code. Is there any one who can help me regarding this, please if possible show me the exact way as well 

JavaMail Questions

JAVA Mail - JavaMail
JAVA Mail  Hi! I am trying to send the mail using SMTP of gmail. program was compiled successfully. when i am trying to execute that program it is showing error --- Must issue STARTTLS command first... How to avoid 

JavaMail Questions

JAVA MAIl - JavaMail
JAVA MAIl  Hi, I am trying to send a mail using java mail api. But I am getting following error: javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect 

Framework Questions

java mail
java mail example  how to download javamail software give one examples   Please visit the following link: Java Mail API 

JavaMail Questions

java mail
java mail  By Which code or function i can send E-mail to given E-mail Address   Hi Friend, Please visit the following link: Java Mail Thanks   Hi Friend, Please visit the following link: Java Mail 

JavaMail Questions

Java Mail API - JavaMail
account using java mail api... i got code from our roseindia.net i.e....Java Mail API  Hi! I wish u advanced happy new year to all of ur...(PKIXValidator.java:280) ... 23 more Java Result: 1 

JSP Servlet Questions

E-Mail header extractor
E-Mail header extractor  i want to extract email header with using of java so please show the code of email extractor as result all the field show different color and or it extract ip where the email came 

JSP Servlet Questions

E-Mail header extractor
E-Mail header extractor  i want to extract email header with using of java so please show the code of email extractor as result all the field show different color and or it extract ip where the email came 

Framework Questions

java mail
java mail  how to download javamail software give one examples   Please visit the following link: Java Mail API 

JSP Servlet Questions

java mail
want to understand the working of Java Mail download the source code from here and learn the coding logic behind Java Mail. You can even compile the source code...java mail  sir, I need a source code to understand 

JavaMail Questions

java mail - JavaMail
java mail  HI! I am developing email client. Using IMAP i am displaying all the messages which are in "INBOX". I want to know how to access remining folders such as "sent", "draft" and others..... Thanks in advance 

JavaMail Questions

Sending mail - JavaMail
emails using outlook client.From java program you can also send email.Here...Sending mail  Need a simple example of sending mail in Java  Hi,To send email you need a local mail server such as apache james. You first 

Java Mail

Forwarding Messages using Java Mail
Forwarding Messages using Java Mail   ... using javamail api. there is no method to forward a mail from one user to another... and get message content then send its for another user. Java code given below 

JavaMail Questions

java mail
java mail  Hi deepak, sorry to trouble again but with reference to apache mail server (james) tutorial i use the link that u have provided it redirects to apache offical site what there 4 zip and taz 

DMCA.com