java mail

java mail

import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import java.util.Properties; public class MailClient {

 public void sendMail(String mailServer, String from, String to,
                         String subject, String messageBody, String[] attachments)
                         throws MessagingException, AddressException
 {
     // Setup mail server
     Properties props = System.getProperties();
     props.put("mail.smtp.host", mailServer);

     // Get a mail session
     Session session = Session.getDefaultInstance(props, null);

     // Define a new mail message
     Message message = new MimeMessage(session);
     message.setFrom(new InternetAddress(from));
     message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
     message.setSubject(subject);

     // Create a message part to represent the body text
     BodyPart messageBodyPart = new MimeBodyPart();
     messageBodyPart.setText(messageBody);

     //use a MimeMultipart as we need to handle the file attachments
     Multipart multipart = new MimeMultipart();

     //add the message body to the mime message
     multipart.addBodyPart(messageBodyPart);

     // add any file attachments to the message
     addAtachments(attachments, multipart);

     // Put all message parts in the message
     message.setContent(multipart);

     // Send the message
     Transport.send(message);


 }

 protected void addAtachments(String[] attachments, Multipart multipart)
                 throws MessagingException, AddressException
 {
     for(int i = 0; i<= attachments.length -1; i++)
     {
         String filename = attachments[i];
         MimeBodyPart attachmentBodyPart = new MimeBodyPart();

         //use a JAF FileDataSource as it does MIME type detection
         DataSource source = new FileDataSource(filename);
         attachmentBodyPart.setDataHandler(new DataHandler(source));

         //assume that the filename you want to send is the same as the
         //actual file name - could alter this to remove the file path
         attachmentBodyPart.setFileName(filename);

         //add the attachment
         multipart.addBodyPart(attachmentBodyPart);
     }
 }

 public static void main(String[] args)
 {
     try
     {
         MailClient client = new MailClient();
         String server="smtp.gmail.com";
         String from="[email protected]";
         String to = "[email protected]";
         String subject="Test";
         String message="Testing";
         String[] filenames = {"c:/somefile.txt"};

         client.sendMail(server,from,to,subject,message,filenames);
     }
     catch(Exception e)
     {
         e.printStackTrace(System.out);
     }

 }

}

Hi..I got this code from a site and im getting the following errors while running.. com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 6sm6761125anx.12

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
    at javax.mail.Transport.send0(Transport.java:191)
    at javax.mail.Transport.send(Transport.java:120)
    at MailClient.sendMail(MailClient.java:52)
    at MailClient.main(MailClient.java:90)

help me clear this error..send suggestions to mail

mail : [email protected]

Thanks.....

View Answers

November 23, 2010 at 12:35 PM

Hi Friend,

Please visit the following link:

Java Mail

Thanks









Related Tutorials/Questions & Answers:
java mail
java mail example  how to download javamail software give one examples   Please visit the following link: Java Mail API
java mail
java mail  By Which code or function i can send E-mail to given E..._TO_REPLACE_1 Java Mail Thanks   Hi Friend,ADS_TO_REPLACE_2 Please visit the following link: Java Mail ThanksADS_TO_REPLACE_3
Advertisements
java mail
java mail  how to download javamail software give one examples   Please visit the following link: Java Mail API
java mail
_TO_REPLACE_2   Hi, Java Mail API is now open source and you can download the source code and read. If you want to understand the working of Java Mail download the source code from here and learn the coding logic behind Java Mail. You
java mail
java mail  import javax.mail.*; import javax.mail.internet....) throws MessagingException, AddressException { // Setup mail...("mail.smtp.host", mailServer); // Get a mail session Session session
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
java mail
java mail  this code showing an error couldn't connect smtp host please help <%@ page language="java" import="javax.naming.*,java.io....(); out.println("Thanks for sending mail!"); } catch(Exception e
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
mail
mail  how to send mail using jsp   Please visit the following links: JSP Send Mail Java Mail Tutorials
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... output.actually,do I need a mail server to get correct output of these codes?plz help me, I
java mail api - JavaMail
java mail api  Hi, Pls give me the detailed information on how... points : 1.Download the Apache Mail server (James) http://james.apache.org... in the classpath. 3.Start the mail server. For read more information,Examples
java mail - Java Beginners
java mail  how to send mail using with out Authentication?????????/ using gmail server
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
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
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
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
what is java mail API - JavaMail
what is java mail API  Please tell me in detail what is java mail API
java mail - JavaMail
java mail  how to send a mail without authentication in java ?  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
JAVA MAIL - JavaMail
JAVA MAIL  Hi! I am doing project called "E-mail Client". In this i want to view attachments which are in my mail in my application. I have tried... application using JAVA MAIL API.  Hi Friend, Please explain us what code
java mail sending with images
java mail sending with images  I need to send images through java mail without giving content path(i.e. we don't want hard code the image path)can you tell me the idea?   Please visit the following links: http
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
Java Mail - JMS
Java Mail  Thanks for the previous jsp answer,that program is now running very well,creating no other problems. Now i am trying to learn java mail... is given below................. //My first java mail program............. import
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 - 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
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
Introduction of Java Mail
Introduction of Java Mail       In this section we will describe Java Mail examples to be used... with attached files. Introduction to Java Mail API
java mail API
java mail API  <html> <head> <title>Mail API<...%" cellpadding="0" cellspacing="0"> <h1>Mail API</h1> <tr>...="submit" value="Send Mail" name="sendMail"></td> </tr> <
Java Mail API - JavaMail
Java Mail API  Hi! I wish u advanced happy new year to all of ur... account using java mail api... i got code from our roseindia.net i.e....(PKIXValidator.java:280) ... 23 more Java Result: 1
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
java mail send using setText()
java mail send using setText()  Hai , Am newly mail send portion in java , Here i write my code , final String userName = "[email protected]... in java file . but if i use set Content() method, mail content is display html
Sending images through java mail
Sending images through java mail  Am trying to develop greeting... and by clicking one image the control go to mail sending page in that the image should add to body part and the mail will sent to recipients..... please give me any idea
Introduction to Java Mail API
Introduction to Java Mail API       The Java Mail API allows the developers to add mailing... with the Java Mail API. The Java Mail API provides a platform-independent framework
Digitally signing email through Java mail api
Digitally signing email through Java mail api  how to sign (Digital Signature) one message using Java mail api
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
Java Mail - JSP-Servlet
Java Mail  hi, i refer ur J2EE Tutorial - Send Email From JSP & Servlet to send emails from my application.but when i run the jsp it will throw thhese exceptions. ERROR.....javax.mail.SendFailedException: Sending failed
java auto mail send - Struts
java auto mail send  Hello, im the beginner for Java Struts. i use java struts , eclipse & tomcat. i want to send mail automatically when the server start..I use the code for send mail..but i dont know how to sent
PHP mail setting - Java Beginners
PHP mail setting  Hai, I want to send an email from my php program... name $email = "[email protected]"; //senders e-mail adress $recipient = "[email protected]"; //recipient $mail_body = "Hai, Greetings
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
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
send without authentication mail using java - JavaMail
send without authentication mail using java  Dear All, I am tring to send simple mail without authentication using java. is it possible, could... props = new Properties(); props.put("mail.smtp.host", "mail host name
How i can send testing mail on my id using java?
How i can send testing mail on my id using java?  Which packages i should use to implementing java mail service??? Thanks
how to make this java mail works? - Java Beginners
how to make this java mail works?  Dear experts, Recently, I... that : The mail package is not part of the Java SDK, you can get the latest... work, for I am really keen to include a java mail inside my application. Now, I
how to get mail exchange records using java dns protocol
how to get mail exchange records using java dns protocol  Hi, how to get DNS mail exchage records(MX) using struts2 framework(server:glassfishv3) Thanks, B.Sucharitha.
Technical description of Java Mail API
Technical description of Java Mail API   ... Mail API. You must understand the Java Mail API before actually delving into the development of mail processing applications. Core classes that makeup the Java
org.simplejavamail - simple-java-mail version 5.0.0 Maven dependency. How to use simple-java-mail version 5.0.0 in pom.xml?
org.simplejavamail  - Version 5.0.0 of simple-java-mail Maven dependency? How to use  org.simplejavamail  - Version 5.0.0 of simple-java-mail in pom.xml? How to use simple-java-mail version 5.0.0 in pom.xml? Learn to use
org.simplejavamail - simple-java-mail version 5.1.2 Maven dependency. How to use simple-java-mail version 5.1.2 in pom.xml?
org.simplejavamail  - Version 5.1.2 of simple-java-mail Maven dependency? How to use  org.simplejavamail  - Version 5.1.2 of simple-java-mail in pom.xml? How to use simple-java-mail version 5.1.2 in pom.xml? Learn to use

Ads