TLS 1.2 with Java Mail
How can I enforce the communication on TLS 1.2 with Java Mail API?
I try to set TLSv1.2 is SSLContext but the communication always takes place on TLSv1.
Please suggest.
Are you setting a new default SSLContext?
By default, JavaMail will use the default SSLSocketFactory, which (I believe) by default will use the default SSLContext.
You can also set the property mail.<protocol>.ssl.protocols to the protocol you want to be used,
which will be passed to the SSLSocket.setEnabledProtocols method.
Similar Messages
-
How to use a progress bar with java mail?
Hi, i'm new here.
I want if someone can recommend me how to show a progress bar with java mail.
Because, i send a message but the screen freeze, and the progress bar never appear, after the send progress finish.
ThanksSo why would the code we post be any different than the code in the tutorial? Why do you think our code would be easier to understand? The tutorial contains explanations about the code.
Did you download the code and execute it? Did it work? Then customize the code to suit your situation. We can't give you the code because we don't know exactly what you are attempting to do. We don't know how you have changed to demo code so that it no longer works. Its up to you to compare your code with the demo code to see what the difference is. -
Only 274 mails are coming when using pop3 with java mail
Only 274 mails are coming from GMAIL when using pop3 with java mail. but there are more than 3000 mails.
I'm not getting the reason, code is given below:
public static void main(String[] args) {
// SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
// String host = "pop.bizmail.yahoo.com";
// final String user = "[email protected]";
// final String password = "xxx";
String host = "pop.gmail.com";
final String user = "gauravjlj";
final String password = "xxx";
String subjectSubstringToSearch = "Test E-Mail through Java";
try {
Properties prop = new Properties();
prop.setProperty("mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.pop3.socketFactory.fallback", "false");
prop.setProperty("mail.pop3.port", "995");
prop.setProperty("mail.pop3.socketFactory.port", "995");
prop.put("mail.pop3.host", host);
prop.put("mail.store.protocol", "pop3");
Session session = Session.getDefaultInstance(prop);
Store store = session.getStore();
System.out.println("your ID is : "+ user);
System.out.println("Connecting...");
store.connect(host, user, password);
System.out.println("Connected...");
// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_ONLY);
int count = fldr.getMessageCount();
System.out.println(count + " total messages");
// Message numebers start at 1
for(int i = 1; i <= count; i++) {
// Get a message by its sequence number
Message m = fldr.getMessage(i);
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
// Search for e-mails by some subject substring
String pattern = subjectSubstringToSearch;
SubjectTerm st = new SubjectTerm(pattern);
// Get some message references
Message [] found = fldr.search(st);
System.out.println(found.length +
" messages matched Subject pattern \"" +
pattern + "\"");
for (int i = 0; i < found.length; i++) {
Message m = found;
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
Object o = m.getContent();
if (o instanceof String) {
System.out.println("**This is a String Message**");
System.out.println((String)o);
else if (o instanceof Multipart) {
System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();
System.out.println("It has " + count3 +
" BodyParts in it**");
for (int j = 0; j < count3; j++) {
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(j);
String mimeType2 = b.getContentType();
System.out.println( "BodyPart " + (j + 1) +
" is of MimeType " + mimeType);
Object o2 = b.getContent();
if (o2 instanceof String) {
System.out.println("**This is a String BodyPart**");
System.out.println((String)o2);
else if (o2 instanceof Multipart) {
System.out.print(
"**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
System.out.println("It has " + count2 +
"further BodyParts in it**");
else if (o2 instanceof InputStream) {
System.out.println(
"**This is an InputStream BodyPart**");
} //End of for
else if (o instanceof InputStream) {
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1) {
System.out.write(c);
// Uncomment to set "delete" flag on the message
//m.setFlag(Flags.Flag.DELETED,true);
} //End of for
// "true" actually deletes flagged messages from folder
fldr.close(true);
store.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
catch (IOException ioex) {
ioex.printStackTrace();
Please tell me.
ThanksIs it possible that GMail only allows access to untagged emails via POP3? Or only to emails from the last x days?
POP3 is the older email retrieval protocol (IMAP4 is the more current one) and only has very limited support for folders (or anything but a single inbox, really). It's quite common that POP3 only allows access to a subset of all emails stored by a provider. -
Hi
We have a requirement to create a custom e mail. For the same I am trying to use Java Mail API.I am facing an issue with the following code:
session session1 = session.getInstance(properties, null);
System gives an error Sourced file: inline evaluation of: ``Properties props = new Properties(); session session1 = session.getInstance(prop . . . '' : Typed variable declaration : Class: session not found in namespace
Is there some specific API i need to import for session class. Kindly suggest.
Regards
ShobhaHi Shobha,
I was also facing the same issue from last couple of weeks and just now i have achieved the working functionality.
Please find below working code and replace values as per your serveru2019s configuration.
import com.sap.odp.api.util.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.File;
import java.net.*;
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to =<email address>;
String from =<email address>;
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = <smtp host name>;
String user = <smtp user name>;
// Create properties, get Session
// Properties props = new Properties();
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.debug", "false");
props.put("mail.smtp.auth", "false");
props.put("mail.user",user);
props.put("mail.from",from);
Session d_session = Session.getInstance(props,null);//Authenticator object need to be set
Message msg = new MimeMessage(d_session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");
Transport.send(msg);
Deepak!!! -
Hello everyone,
Iam sending mail using java, my mail format consisit of colored text and images,that should be diplsyed to reciever in mail box,my code is working fine reciever gets mail in inbox but problem is when we recieve mail like that images doesnot show up in the mail automaticaly,when i click on show images link in my mail box only then images become visible,i tested my mail in gmail,rediff and yahoo and in all cases i have to mannually click on "show images" link to view images that i sent with my mail,why so? is this due to security reasons in mailbox??? can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.
Please help.
Thanks.anie wrote:
can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.No. That's a security function of the browser, and not something you can control.
On another note, please refrain from posting unnecessary, excessive punctuation. It only clutters up your message, which isn't a good thing. Thanks!
~ -
Having Trouble with Java Mail and Servlets
How can I send and receive mails using Java Mail API and Servlets
You should familiarize yourself with the JavaMail API and the servlet API--this is much too broad a question to properly answer in a forum. The J2EE Tutorial shows how to send a mail message using JavaMail from a session bean, but the technique is similar to what you would use from a servlet:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Resources5.html#wp82097
I'm sure the JavaMail documentation has an example as well.
-Ian Evans -
Can I FAX with JAVA MAIL??
Any body can help me with some key code to fax with my Java mail?? What are the other requirements apart from JAVA MAIL API???
Thanking you
AchintyaHello! Achintya, what I know is you need to hv a service provider to convert yr e-mail into fax format & send to the destination.
iSam
[email protected] -
How to send image as a part of body with java mail
How to send image (.GIF) file in mail body & not as an attachement using java mail API
You need to create a multipart/related message.
You'll probably find examples in this forum. -
Error Compiling With java.mail.Session class
Hi,
The Java compiler issues an error message (below) during compilation of the following line:
Session session = Session.getDefaultInstance( fMailServerConfig, null );
The error message is:
bad class file: c:\j2ee_sdk\lib\j2ee.jar(javax/mail/Session.class)
class file has wrong version 48.0, should be 47.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
javax.mail.Session session = javax.mail.Session.getDefaultInstance( fMailServerConfig, null );
I have tried switching between JDKs by changing the JAVA_HOME environment variable between JDKs 1.3.x to 1.4.x to 1.5.x and also to the JDK installed with the 2005 Q1 J2EE installation that I am using.
Any ideas on how to resolve this problem? And help would be GREATLY appreciated.
Thanks!!!
Stuart Hoffmanin Session session = Session.getDefaultInstance( fMailServerConfig, null ); pass the object of properties class instead of mailServerconfig
now your problem are solved -
Problem with Java Mail Program
Hi Everyone...
Please help me to sort out this problem...
I am getting this Exception while executing the code pasted below...
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at JDCSend.main(JDCSend.java:38)
It's just a simple java program to send an email using JavaMail API
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
import java.util.Properties;
public class JDCSend {
public static void main (String args[]) {
try{
String from = "[email protected]";
String to = "[email protected]";
String host = "smtp.yahoo.com";
// Get system properties
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", 465);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello, JDC");
message.setText("Welcome to the JDC");
// Send message
Transport.send(message);
catch(Exception e){ e.printStackTrace(); }
}You need to be identified by stmp server :
// Send message with authentication!
Transport tr = session.getTransport("smtp");
tr.connect(MailHost, user, pass);
message.saveChanges(); // don't forget this
tr.sendMessage(message, message.getAllRecipients());
tr.close();
Read JavaMail Faq please! -
Anybody there familiar with Java Mail API ???? I need help
I have a problem using the MessageCount Listener in mail API... Problem is simple........... The Listener doesn't work at all...
Has anyone tried it out .. Please reply if u have so that i can present the real picture.... Please dont avoid me by giving links to tutorials... Believe me... i've tried a few of them but nothing seems to help me...Hai pal,
I'm using a pop3 account.. Here i tried using the getmessagecount command... But it doesn't work.. Its showing the same count every time in spite of new messages arriving. The listener doesn't fire at all..
To get the folder show updated count, i have to close and reopen the folder. This itself makes the concept of message listeners quite vague... Do u have any further tips on this..
Thanks
Dst -
Exception in java mail API when parsing email
I am receiving the following exception when receiving some emails that contain attachments with java mail (irrelevant part of stack trace omitted):
javax.mail.internet.ParseException: Expected ';', got ","
at javax.mail.internet.ParameterList.<init>(ParameterList.java:289)
at javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:100)
at javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:1136)
The header of a message the causes the problem is:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) ------------ Message headers ------------
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from mail2.uscourts.gov ([10.170.250.2])
by ushub06.uscmail.dcn (Lotus Domino Release 8.5.2FP1 HF3)
with SMTP id 2011042514392620-733724 ;
Mon, 25 Apr 2011 14:39:26 -0400
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from (unknown [63.174.91.123]) by avms-usc-04c-02vh.ibmta.uscourts.gov with smtp
id 191c_067d_57fad3b8_6f6b_11e0_8de9_00265519f638;
Mon, 25 Apr 2011 18:39:24 +0000
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-WSS-ID: 0LK815L-05-67D-02
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-M-MSG:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from kcmexclaim.Our-Firm.com (unknown [10.42.5.222])by mail4.stinson.com (Axway MailGate 3.8.1) with ESMTP id 27239A12C1D; Mon, 25 Apr 2011 13:39:20 -0500 (CDT)
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from KCME2K7-HUB02.Our-Firm.com ([10.42.5.19]) by kcmexclaim.Our-Firm.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 25 Apr 2011 13:39:23 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from FIRMCMS01.Our-Firm.com ([fe80::81d0:dd2b:9983:1126]) by KCME2K7-HUB02.Our-Firm.com ([::1]) with mapi; Mon, 25 Apr 2011 13:39:22 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) From:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) To:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Cc:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Disposition-Notification-To:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Date: Mon, 25 Apr 2011 13:39:21 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Subject: Order Regarding Application To Employ SMH as Debtor's Counsel
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Thread-Topic: Order Regarding Application To Employ SMH as Debtor's Counsel
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Thread-Index: AcwDb/bpRQlxt/eTQC6BA7G10hdWJQAB99vQ
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Message-ID: <[email protected]>
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Accept-Language: en-US
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-MS-Has-Attach: yes
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-MS-TNEF-Correlator:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) acceptlanguage: en-US
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Importance: Normal
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Priority: normal
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4841
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) MIME-Version: 1.0
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Return-Path:
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-OriginalArrivalTime: 25 Apr 2011 18:39:23.0526 (UTC) FILETIME=[18E10260:01CC0378]
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-MIMETrack: Itemize by SMTP Server on USHUB06/H/US/USCOURTS(Release 8.5.2FP1 HF3|December 21, 2010) at 04/25/2011 02:39:26 PM, Serialize by POP3 Server(Release 8.0.2FP3 HF28|December 28, 2009) at 04/25/2011 02:39:47 PM
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Transfer-Encoding: 7bit
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Class: urn:content-classes:message 2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Type: multipart/mixed; boundary="_004_52835C1F7A6C8D4F989C433DCC611CA06F252D6682FIRMCMS01OurF_"
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Language: en-US
the client/OS combination of the mail sender is Windows XP service Pack 3/Outlook 2007 , Java Mail version 1.4.3
Any help would be appreciated
Edited by: 854778 on Apr 26, 2011 8:28 AMThe exception is occurring when parsing the Content-Disposition header.
I don't see that header in the list of headers you provided.
Can you save the entire message to a text file using
msg.writeTo(new FileOutputStream("msg.txt"));
Then look for the Content-Disposition header in msg.txt. Most likely you'll
find that it is incorrectly formatted - as the exception says, there's a comma
in a place that a semicolon is expected. -
I have tried to run and deploy demo web app that comes with java mail 1.3, but while logging i have got the following error:
javax.mail.MessagingException: Connection timed out: connect; nested exception is: java.net.ConnectException: Connection timed out: connect
And while sending message it generates the following error:
A Servlet Exception Has Occurred
org.apache.jasper.JasperException: This absolute uri (http://java.sun.com/products/javamail/demo/webapp) cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:194)
at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:174)
at org.apache.jasper.compiler.JspParseEventListener.processTaglibDirective(JspParseEventListener.java:1148)
at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:755)
at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:121)
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:243)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1132)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1091)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1087)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:213)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:210)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:543)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:1264)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:430)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:354)
at FilterServlet.doPost(FilterServlet.java:61)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:1145)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:1264)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1005)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1098)
at java.lang.Thread.run(Thread.java:534)
Please send me a fully working war file if any one have with the web server used ! Please I have to subit this as my assignment!You might want to try the latest version of that app included
with JavaMail 1.4. It has a few fixes that might help you.
Hopefully you're not going to take credit for this with your
assignment. :-) -
I am new with Java mail
I research throug internet and i end up downloading javamail 1.4
in the read me file there some directions to install javamail package on window, linux and unix.
does it mean since i have a mac i can not install it?
if i can how?am using eclipse 3.2 and jvm 1.5 mac os
i try to add a import javax.mail.* in my code but eclipse does n recognize it
What should i do to get this rolling
Thanks for your helpI think we've been around this loop once already, and I thought you
said earlier that it was working.
When I say "import the jar file", I don't mean "add an import
statement in your Java source code" (although you need to do
that as well). I mean that you have to do something in your
Eclipse project to tell it where to find the mail.jar file and add
it to your project. Sorry, I'm not an Eclipse user so I can't tell
you exactly how to do that. -
Hi,
I have one prob with java mail .. How do i display file content in email ...
When i pass content as String(suppose hello) it displays hello in email ....How do i display file content in html form when user opens his email .....
Any help on this i will appriciate ..........
Thanks.Hi,
I have one jsp file and this file includes some include files ......
How do i send this jsp file as body of email using java mail ................
I did this by hot coding the tags and content ... i have to read from jps file and this file include some images ...........
Here is my code ... Please can any one help me ....
import java.io.*;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class sendhtml {
public static void sendMess(String[] argv) {
String to, subject = "hello", from = null,
cc = null, bcc = null, url = null;
String mailhost = "xx.xxx.xx.xx";
String mailer = "sendhtml";
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
try {
to="[email protected]";
Properties props = System.getProperties();
// could use Session.getTransport() and Transport.connect()
// assume we're using SMTP
if (mailhost != null)
props.put("mail.smtp.host", mailhost);
// Get a Session object
Session session = Session.getDefaultInstance(props, null);
if (debug)
session.setDebug(true);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false));
msg.setSubject(subject);
MimeMultipart mp = new MimeMultipart();
mp.setSubType("related");
MimeBodyPart mbp1= new MimeBodyPart();
String html =
"<html>"+
"<head><title></title></head>"+
"<body>"+
"<b> see the following jpg : it is a car! !!!!!</b><br>"+
"<a href=a.jsp>hello</a><br>"+
"<img src=cid:123 >"+
"<IMG SRC=cid:23 ><br>"+
"<b> end of jpg</b>"+
"<table><tr><td>"+
"Every couple days for the next four weeks, we will send you new"+
"can successfully sell your home.<br><br></td></tr>"+
"<tr><td>"+
"<p class=\"letter\">"+
"saleMail Topics are: <br><br>"+
"<ol class=\"letter\">"+
"<li><b>Advertising Your Home: Part 2</b></li>"+
"<li><b> Possibilities</b></li>"+
"<li><b>Where Do You Go From Here?</b></li>"+
"</ol>"+
"<br><br></p></td></tr></table>"+
"</body>"+
"</html>";
mbp1.setContent(html,"text/html");
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource("/usr/local/images/dualsign.gif");
mbp2.setFileName(fds.getName());
mbp2.setText("This is a beautiful car !");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setHeader("Content-ID","23");
FileDataSource fds1 = new FileDataSource("/usr/local/images/logo.gif");
mbp2.setFileName(fds1.getName());
mbp2.setText("This is a beautiful car !");
mbp2.setDataHandler(new DataHandler(fds1));
mbp2.setHeader("Content-ID","123");
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println(mp.getCount());
System.out.println("\nMail was sent successfully.");
} catch (Exception e) {
e.printStackTrace();
Maybe you are looking for
-
Link title not displaying properly in fact sheet
Hi experts, I have an issue with fact sheet of BP here, the link titles, e.g. "Activities", "Account Billing Data", "Account Sales Data" etc are displaying like "BP_FACTSHEET0001", "BP_FACTSHEET0002"... I checked configuration in IMG CRM->UI Framewor
-
[SOLVED] systemd --user: "Failed to open private bus connection:"
EDIT: The solution was to set DBUS_SESSION_BUS_ADDRESS, as suggested by gtmanfred in irc. By putting the following before executing systemd --user, the error vanished: export DBUS_SESSION_BUS_ADDRESS=/run/user/$(id -u)/dbus/user_bus_socket =========
-
HP p7-1459 Compatibility Issues
I was wondering if my Radeon 5570HD http://www.newegg.ca/Product/Product.aspx?Item=N82E16814102874 compatable with the Joshua Mother Board. When I installed it the computer would start but i would have no video output so I'm guessing no?
-
How can I specific user's right ?
I have studied ACS4 working flow from sample shop and document. But I still have some question about right to download ebook. After sample shop generate GBLink and user download acsm file. Is it possible to specific that acsm file can only open by sp
-
I have three problems. Most important and most immediate: I am unable to log in to Mail (the In Box is gray), although I have an Internet connection (I have had this problem before, but it seemed to be a connection problem, which I solved by resettin