Search Results

Search found 119 results on 5 pages for 'javamail'.

Page 2/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • why javamail fails with an authentication Exception ?

    - by saravana
    package com.bcs; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendMailTLS { public static void main(String[] args) { String host = "smtp.gmail.com"; int port = 587; String username = "[email protected]"; String password = "bar"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(props); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("")); message.setSubject("Testing Subject"); message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!"); Transport transport = session.getTransport("smtp"); transport.connect(host, port, username, password); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } } I have given all the necessary inputs . But still it fails with Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: failed to connect, no password specified? at com.bcs.SendMailTLS.main(SendMailTLS.java:43) Caused by: javax.mail.AuthenticationFailedException: failed to connect, no password specified? at javax.mail.Service.connect(Service.java:329) at javax.mail.Service.connect(Service.java:176) at javax.mail.Service.connect(Service.java:125) at javax.mail.Transport.send0(Transport.java:194) at javax.mail.Transport.send(Transport.java:124) at com.bcs.SendMailTLS.main(SendMailTLS.java:38) I am new to java mail.Any help would be greatly appreciated.

    Read the article

  • JavaMail: Could not connect to SMTP server.

    - by javacode
    Hi The following code causes an error. Please help me understand what's wrong. import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class SendMail { public static void main(String [] args)throws MessagingException { SendMail sm=new SendMail(); sm.postMail(new String[]{"[email protected]"},"hi","hello","[email protected]"); } public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", "webmail.emailmyname.com"); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Optional : You can also set your custom headers in the Email if you Want msg.addHeader("MyHeaderName", "myHeaderValue"); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); } } Exception: <pre> com.sun.mail.smtp.SMTPSendFailedException: 450 smtpout04.dca.untd.com Authentication required 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 SendMail.postMail(SendMail.java:52) at SendMail.main(SendMail.java:10)

    Read the article

  • JavaMail - javax.mail.MessagingException

    - by legendofawesomeness
    I am trying to write a simple mail sender class that would receive a bunch of arguments and using those will send an email out using our Exchange 2010 server. While authentication etc. seem to work fine, I am getting the following exception when the code is actually trying to send the email (I think). I have ensured that the authentication is working and I get a transport back from the session, but still it fails. Could anyone shed some like on what I am doing wrong or missing? Thanks. Exception: javax.mail.MessagingException: [EOF] at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481) at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634) at javax.mail.Transport.send0(Transport.java:189) at javax.mail.Transport.send(Transport.java:140) at com.ri.common.mail.util.MailSender.sendHTMLEmail(MailSender.java:75) at com.ri.common.mail.util.MailSender.main(MailSender.java:106) Relevant code: import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class MailSender { public static void sendHTMLEmail( String fromEmailId, String toEmailId, String host, String hostUserName, String hostPassword, String mailSubject, String mailBody ) { // Get system properties. Properties props = System.getProperties(); // Setup mail server props.put( "mail.transport.protocol", "smtp" ); props.put( "mail.smtp.host", host ); props.put( "mail.smtp.auth", "true" ); final String hostUName = hostUserName; final String hPassword = hostPassword; Authenticator authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( hostUName, hPassword ); } }; // Get the default Session object. Session session = Session.getDefaultInstance( props, authenticator ); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage( session ); // Set From: header field of the header. message.setFrom( new InternetAddress( fromEmailId ) ); // Set To: header field of the header. message.addRecipient( Message.RecipientType.TO, new InternetAddress( toEmailId ) ); // Set Subject: header field message.setSubject( mailSubject ); // Send the actual HTML message, as big as you like message.setContent( mailBody, "text/html" ); // Send message Transport.send( message, message.getAllRecipients() ); System.out.println( "Sent message successfully...." ); } catch( Exception mex ) { mex.printStackTrace(); } } public static void main( String[] args ) { String to = "[email protected]"; String from = "[email protected]"; String host = "correctHostForExch2010"; String user = "correctUser"; String password = "CorrectPassword"; String subject = "Test Email"; String body = "Hi there. This is a test email!"; MailSender.sendHTMLEmail( from, to, host, user, password, subject, body ); } } EDIT: I turned on debugging and it says MAIL FROM:<[email protected]> 530 5.7.1 Client was not authenticated DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated. Why would that be when the session authentication succeded?

    Read the article

  • Using JavaMail to send a mail containing Unicode characters

    - by NoozNooz42
    I'm successfully sending emails through GMail's SMTP servers using the following piece of code: Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); props.put("mail.smtp.ssl", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.timeout", "5000"); props.put("mail.smtp.connectiontimeout", "5000"); // Do NOT use Session.getDefaultInstance but Session.getInstance // See: http://forums.sun.com/thread.jspa?threadID=5301696 final Session session = Session.getInstance( props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( USER, PWD ); } }); try { final Message message = new MimeMessage(session); message.setFrom( new InternetAddress( USER ) ); message.setRecipients( Message.RecipientType.TO, InternetAddress.parse( TO ) ); message.setSubject( emailSubject ); message.setText( emailContent ); Transport.send(message); emailSent = true; } catch ( final MessagingException e ) { e.printStackTrace(); } where emailContent is a String that does contain Unicode characters (like the euro symbol). When the email arrives (in another GMail account), the euro symbol has been converted to the ASCII '?' question mark. I don't know much about emails: can email use any character encoding? What should I modify in the code above so that an encoding allowing Unicode characters is used?

    Read the article

  • Netbeans: Using JavaMail in normal Java projects

    - by Yohan
    I am creating an desktop application which is capable of sending emails. I downloaded mail.jar and javaee.jar and added it to my project libraries. However, when I am trying to use it, it gives me the error java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Uncompilable source code - package javax.mail does not exist I imported those packages as, import javax.mail.* It added correctly, as shown in the following image. Please help!! How can I make this work?

    Read the article

  • Inconsistent email formatting with inline css created using Javamail

    - by user1816183
    Okay, so I have a program that sends an email when it is finished running. I use inline css to format the email. This was working up until yesterday however now I am seeing different formats depending on which email account I view the email in. It coincides with an upgrade from Selenium 2.35.0 to 2.37.0 however I don't think this is my issue since I rolled back to 2.35.0 and it still happens. package tests; import java.util.Properties; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class TESTTEST { public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put("mail.smtp.host","xxx.xxx.xxx.xxx"); Session session = Session.getInstance(props); String emailFrom="[email protected]"; String emailTo1="[email protected]"; MimeMessage message = new MimeMessage(session); message.setSubject("Testing HTML Email"); message.setFrom(new InternetAddress(emailFrom)); String htmlBody = "<STYLE>body {font-family:sans-serif,arial,helvetica,sans-serif;font-size:9pt;}" +"TABLE {border-collapse:collapse;border:1px solid black;}" +"TH {background-color:grey;color:white;padding:5px;border:1px solid black;font-size:9pt;}" +"TD {padding:5px;border:1px solid black;font-size:9pt;}" +"H3 {font-size:12pt;}" +".PASSED {background-color:#00FF00}" +".FAILED {background-color:#FF0000}" +".SKIPPED {background-color:#DEDEDE}" +".ITALIC {font-style:italic}" +"</STYLE>" + "<TABLE><TR><TD CLASS=PASSED>FAIL</TD><TD STYLE=background-color:#FF0000>FAIL</TD></TR></TABLE>"; message.setContent(htmlBody, "text/html; charset=ISO-8859-1"); message.addRecipient(Message.RecipientType.TO,new InternetAddress(emailTo1)); Transport.send(message,message.getRecipients(Message.RecipientType.TO)); System.out.println(htmlBody); System.out.println("Email Sent"); } } When I view the email in Hotmail/Outlook.com, it looks fine In Gmail In Lotus Notes Anybody able to help?

    Read the article

  • how to get recipients addresses as String in JavaMail?

    - by Neuquino
    I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching I the difference is that I need to get the "TO" addresses as a String. I can't find in the API how to get the "TO" recipients as String for each Message. Can anyone guide me on how to do this? At least a link where someone has already done it. Thanks in advance

    Read the article

  • How do I send an email with embedded images AND regular attachments in JavaMail?

    - by Chris
    Hi, I'd like to know how to build an SMTP multipart message in the correct order so that it will render correctly on the iPhone mail client (rendering correctly in GMail). I'm using Javamail to build up an email containing the following parts: A body part with content type "text/html; UTF-8" An embedded image attachment. A file attachment I am sending the mail via GMail SMTP (via SSL) and the mail is sent and rendered correctly using a GMail account, however, the mail does not render correctly on the iPhone mail client. On the iPhone mail client, the image is rendered before the "Before Image" text when it should be rendered afterwards. After the "Before Image" text there is an icon with a question mark (I assume it means it couldn't find the referenced CID). I'm not sure if this is a limitation of the iPhone mail client or a bug in my mail sending code (I strongly assume the latter). I think that perhaps the headers on my parts might by incorrect or perhaps I am providing the multiparts in the wrong order. I include the text of the received mail as output by gmail (which renders the file correc Message-ID: <3977333.1.1274154021787.JavaMail[email protected]> Subject: =?UTF-8?Q?Test_from_=E3=82=AF=E3=83=AA=E3=82=B9?= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_20870565.1274154021755" ------=_Part_0_20870565.1274154021755 Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-ID: <20100518124021763_368238_0> iVBORw0K ----- TRIMMED FOR CONCISENESS 6p1VVy4alAAAAABJRU5ErkJggg== ------=_Part_0_20870565.1274154021755 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <html><head><title>Employees Favourite Foods</title> <style> body { font: normal 8pt arial; } th { font: bold 8pt arial; white-space: nowrap; } td { font: normal 8pt arial; white-space: nowrap; } </style></head><body> Before Image<br><img src="cid:20100518124021763_368238_0"> After Image<br><table border="0"> <tr> <th colspan="4">Employees Favourite Foods</th> </tr> <tr> <th align="left">Name</th><th align="left">Age</th><th align="left">Tel.No</th><th align="left">Fav.Food</th> </tr> <tr style="background-color:#e0e0e0"> <td>Chris</td><td>34</td><td>555-123-4567</td><td>Pancakes</td> </tr> </table></body></html> ------=_Part_0_20870565.1274154021755 Content-Type: text/plain; charset=us-ascii; name=textfile.txt Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=textfile.txt This is a textfile with numbers counting from one to ten beneath this line: one two three four five six seven eight nine ten(no trailing carriage return) ------=_Part_0_20870565.1274154021755-- Even if you can't assist me with this, I would appreciate it if any members of the forum could forward me a (non-personal) mail that includes inline images (not external hyperlinked images though). I just need to find a working sample then I can move past this. Thanks, Chris.

    Read the article

  • JavaMail SMTP credentials verification, without actually sending an email.

    - by DarK
    Hi, Is there a way to check user SMTP server credentials without sending email, or connecting to POP/IMAP. Some code I tried to write, fails at it. Can you find what is missing there. Don't worry about Email / password. I know it's there. NOTE : If you are trying out the code. The case 1 should pass when supplying the correct credentials. If it fails, then someone changed the password. You should use some other email address. import java.util.Properties; import javax.mail.Authenticator; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; public class EmailTest { public static void main(String[] args) { EmailHelper eh = new EmailHelper(); /* GMail Setting for SMTP using STARTTLS */ String name = "AAA"; String email = "[email protected]"; String smtpHost = "smtp.gmail.com"; String serverPort = "587"; String requireAuth = "true"; String dontuseAuth = "false"; String userName = email; // same as username for GMAIL String password = "zaq12wsx"; String incorrectPassword = "someRandomPassword"; String enableSTARTTLS = "true"; String dontenableSTARTTLS = "false"; try { /* only valid case */ eh.sendMail(name, email, smtpHost, serverPort, requireAuth, userName, password, enableSTARTTLS); System.out.println("Case 1 Passed"); /* should fail since starttls is required for GMAIL. */ eh.sendMail(name, email, smtpHost, serverPort, requireAuth, userName, password, dontenableSTARTTLS); System.out.println("Case 2 Passed"); /* should fail since GMAIL requires authentication */ eh.sendMail(name, email, smtpHost, serverPort, dontuseAuth, "", "", dontenableSTARTTLS); System.out.println("Case 3 Passed"); /* should fail. password is incorrect and starttls is not enabled */ eh.sendMail(name, email, smtpHost, serverPort, requireAuth, userName, incorrectPassword, dontenableSTARTTLS); System.out.println("Case 4 Passed"); } catch (MessagingException e) { e.printStackTrace(); } } } class EmailHelper { private Properties properties = null; private Authenticator authenticator = null; private Session session = null; public void sendMail(String name, String email, String smtpHost, String serverPort, String requireAuth, String userName, String password, String enableSTARTTLS) throws MessagingException { properties = System.getProperties(); properties.put("mail.smtp.host", smtpHost); properties.put("mail.smtp.port", serverPort); properties.put("mail.smtp.starttls.enable", enableSTARTTLS); properties.put("mail.smtp.auth", requireAuth); properties.put("mail.smtp.timeout", 20000); authenticator = new SMTPAuthenticator(userName, password); session = Session.getInstance(properties, authenticator); // session.setDebug(true); Transport tr = session.getTransport("smtp"); tr.connect(); /* * do I need more than just connect? Since when i try to send email with * incorrect credentials it fails to do so. But I want to check * credentials without sending an email. Assume that POP3/IMAP username * is not same as the SMTP username, since that might be one of the * cases */ } } class SMTPAuthenticator extends Authenticator { private String userName = null; private String password = null; public SMTPAuthenticator(String userName, String password) { this.userName = userName; this.password = password; } @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }

    Read the article

  • How do I configure a mail server for use with JavaMail?

    - by bobby
    I'm trying to work with the below code: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import javax.mail.*; import javax.mail.internet.*; // important import javax.mail.event.*; // important import java.net.*; import java.util.*; public class servletmail extends HttpServlet { public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out=response.getWriter(); response.setContentType("text/html"); try { Properties props=new Properties(); props.put("mail.smtp.host","localhost"); // 'localhost' for testing Session session1 = Session.getDefaultInstance(props,null); String s1 = request.getParameter("text1"); //sender (from) String s2 = request.getParameter("text2"); String s3 = request.getParameter("text3"); String s4 = request.getParameter("area1"); Message message =new MimeMessage(session1); message.setFrom(new InternetAddress(s1)); message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(s2,false)); message.setSubject(s3); message.setText(s4); Transport.send(message); out.println("mail has been sent"); } catch(Exception ex) { System.out.println("ERROR....."+ex); } } } I'm using mail.jar and activation.jar. But I can't understand how I should configure it with a mail server. Which mail server should I use? Will I be able to send an email using above code? What are the requirements a mail server? How should I configure it?

    Read the article

  • Missing ant-javamail.jar file on Macintosh

    - by Ken
    I've been running the built-in Ant from the command line on a Macintosh (10.5.5) and have run into some trouble with the Mail task. Running the Mail task produces the following message: [mail] Failed to initialise MIME mail: org.apache.tools.ant.taskdefs.email.MimeMailer This is most likely due to a missing ant-javamail.jar file in the /usr/share/ant/lib directory. I see a "ant-javamail-1.7.0.pom" file in this directory but not the appropriate jar file. Anyone know why this jar file might be missing and what the best way to resolve the problem is?

    Read the article

  • JavaMail application won't send email to external SMTP server

    - by Luiz Cruz
    This is actually a question from an exam, but I believe it could help others troubleshooting a similar situation. In a system, an e-mail needs to be sent to a certain mailbox. The following Java code, which is part of a larger system, was developed for that. Assume that "example.com" corresponds to a valid registered internet domain. public void sendEmail(){ String s1=”Warning”; String b1=”Contact IT support.”; String r1=”[email protected]”; String d1=”[email protected]”; String h1=”mx.intranet”; Properties p1 = new Properties(); p1.put(“mail.host”, h1); Session session = Session.getDefaultInstance(p1, null); MimeMessage message = new MimeMessage(session); try { message.setFrom(new InternetAddress(r1)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(d1)); message.setSubject(s1); message.setText(b1); Transport.send(message); } catch (MessagingException e){ System.err.println(e); } } The execution of this code, within the testing environment of an application server, does NOT work as expected. The mailbox of the "example.com" server never receives the email, even tough all string values in the code are correctly attributed. The output for the command "netstat -np TCP" in the application server during execution is shown bellow: Src Add Src Port Dest Add Dest Port State 192.168.5.5 54395 192.168.7.1 25 SYN_SENT 192.168.5.5 54390 192.168.7.1 110 TIME_WAIT 192.168.5.5 52001 200.218.208.118 80 CLOSE_WAIT 192.168.5.5 52050 200.218.208.118 80 ESTABLISHED 192.168.5.5 50001 200.255.94.202 25 TIME_WAIT 192.168.5.5 50000 200.255.94.202 25 ESTABLISHED With the exception of the lines that were NAT'd, all others are associated with the Java application server, which created them after the execution of the code above. The e-mail server used in this environment is the production server, which is online and does not require any authentication for internal connections. Based on this situation, point out three possible causes for the problem.

    Read the article

  • How to resovle javax.mail.AuthenticationFailedException issue?

    - by jl
    Hi, I am doing a sendMail Servlet with JavaMail. I have javax.mail.AuthenticationFailedException on my output. Can anyone please help me out? Thanks. sendMailServlet code: try { String host = "smtp.gmail.com"; String from = "[email protected]"; String pass = "pass"; Properties props = System.getProperties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); Address fromAddress = new InternetAddress(from); Address toAddress = new InternetAddress("[email protected]"); message.setFrom(fromAddress); message.setRecipient(Message.RecipientType.TO, toAddress); message.setSubject("Testing JavaMail"); message.setText("Welcome to JavaMail"); Transport transport = session.getTransport("smtp"); transport.connect(host, from, pass); message.saveChanges(); Transport.send(message); transport.close(); }catch(Exception ex){ out.println("<html><head></head><body>"); out.println("ERROR: " + ex); out.println("</body></html>"); } Output on GlassFish 2.1: DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false 220 mx.google.com ESMTP 36sm10907668yxh.13 DEBUG SMTP: connected to host "smtp.gmail.com", port: 587 EHLO platform-4cfaca 250-mx.google.com at your service, [203.126.159.130] 250-SIZE 35651584 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 PIPELINING DEBUG SMTP: Found extension "SIZE", arg "35651584" DEBUG SMTP: Found extension "8BITMIME", arg "" DEBUG SMTP: Found extension "STARTTLS", arg "" DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" DEBUG SMTP: Found extension "PIPELINING", arg "" STARTTLS 220 2.0.0 Ready to start TLS EHLO platform-4cfaca 250-mx.google.com at your service, [203.126.159.130] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250 PIPELINING DEBUG SMTP: Found extension "SIZE", arg "35651584" DEBUG SMTP: Found extension "8BITMIME", arg "" DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN" DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" DEBUG SMTP: Found extension "PIPELINING", arg "" DEBUG SMTP: Attempt to authenticate AUTH LOGIN 334 VXNlcm5hbWU6 aWpveWNlbGVvbmdAZ21haWwuY29t 334 UGFzc3dvcmQ6 MTIzNDU2Nzhf 235 2.7.0 Accepted DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true

    Read the article

  • Java Mail timeout & connectiontimeout handling

    - by Gnanam
    Hi, I'm using JavaMail to send email requests to an SMTP server. I would like to set both "mail.smtp.connectiontimeout" and "mail.smtp.timeout" properties within my code. Programmatically, I want to catch both when timeout and/or connectiontimeout operations are reached in Java and handle things accordingly. Handling in the sense, I need to retry the same email once again the next time. How do I handle this in Java/JavaMail? Is it possible to catch & handle this timeout operations?

    Read the article

  • sending mail to any website using java servlet

    - by mrig
    I am using javamail api in java servlet to send mail. It seams to send mail only to gmail Id's, whereas I want it to be able to send to any email ID. Do I require different property value here? I followed http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ to develop the code. The property values are: props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.setProperty("mail.smtp.port", "587"); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.starttls.enable", "true");

    Read the article

  • Sending multi-part email from Google App Engine using Spring's JavaMailSender fails

    - by hleinone
    It works without the multi-part (modified from the example in Spring documentation): final MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(final MimeMessage mimeMessage) throws Exception { final MimeMessageHelper message = new MimeMessageHelper( mimeMessage); message.setTo(toAddress); message.setFrom(fromAddress); message.setSubject(subject); final String htmlText = FreeMarkerTemplateUtils .processTemplateIntoString(configuration .getTemplate(htmlTemplate), model); message.setText(htmlText, true); } }; mailSender.send(preparator); But once I change it to: final MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(final MimeMessage mimeMessage) throws Exception { final MimeMessageHelper message = new MimeMessageHelper( mimeMessage, true); ... message.setText(plainText, htmlText); } }; mailSender.send(preparator); I get: Failed message 1: javax.mail.MessagingException: Converting attachment data failed at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:231) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:402) ... This is especially difficult since the GMTransport is proprietary Google class and no sources are available, which would make it a bit easier to debug. Anyone have any ideas what to try next? My bean config, for helping you to help me: <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" p:username="${mail.username}" p:password="${mail.password}" p:protocol="gm" />

    Read the article

  • How to enable attachment using Apache File upload

    - by Stardust
    I am using Apache commons File upload API to Store the file from JSP to servlets in temp directory, but I don't know what should I do next to send the email as an attachment using javamail API. How can I retrieve those files which is written in temp directory using Apache Fileupload API to send them as attachment to mail Server. How will writing those files either to memory or disk will help me?

    Read the article

  • how to know the protocol from servlets

    - by Dusk
    If I need to get inbox messages by passing request from servlets to javamail API , how can I know the protocol in which to retrieve inbox messages? Do I have to state the protocol in request URL? I've already checked in gmail, where they haven't stated any protocol, then How can I get inbox messages based on particular protocol like: POP3 or IMAP

    Read the article

  • getting base64 content string of an image from a mimepart in Java

    - by Bas van den Broek
    Hello, I am trying to get the base64 content of a MimePart in a MimeMultiPart, but I'm struggling with the Javamail package. I simply want the base64 encoded String of a certain inline image, there doesn't seem to be an easy way to do this though. I wrote a method that will take the mime content (as a string) and an image name as a parameter, and searches for the part that contains the base64 content of that image name, and in the end returns this base64 string (as well as the content type but that is irrelevant for this question) Here is the relevant code: private static String[] getBase64Content(String imageName, String mimeString) throws MessagingException, IOException { System.out.println("image name: " + imageName + "\n\n"); System.out.println("mime string: " + mimeString); String[] base64Content = new String[2]; base64Content[0] = ""; base64Content[1] = "image/jpeg"; //some default value DataSource source = new ByteArrayDataSource(new ByteArrayInputStream(mimeString.getBytes()), "multipart/mixed"); MimeMultipart mp = new MimeMultipart(source); for (int i = 0; i < mp.getCount(); i++) { MimePart part = (MimePart) mp.getBodyPart(i); String disposition = part.getDisposition(); if (disposition != null && disposition.equals(Part.INLINE)) { if (part.getContentID() != null && part.getContentID().indexOf(imageName) > -1) //check if this is the right part { if (part.getContent() instanceof BASE64DecoderStream) { BASE64DecoderStream base64DecoderStream = (BASE64DecoderStream) part.getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(base64DecoderStream, writer); String base64decodedString = writer.toString(); byte[] encodedMimeByteArray = Base64.encodeBase64(base64decodedString.getBytes()); String encodedMimeString = new String(encodedMimeByteArray); System.out.println("encoded mime string: " + encodedMimeString); base64Content[0] = encodedMimeString; base64Content[1] = getContentTypeString(part); } } } } return base64Content; } I cannot paste all of the output as the post would be too long, but this is some of it: image name: [email protected] This is a part of the mimeString input, it does find this (correct) part with the image name: --_004_225726A14AF9134CB538EE7BD44373A04D9E3F3940menexch2007ex_ Content-Type: image/gif; name="image001.gif" Content-Description: image001.gif Content-Disposition: inline; filename="image001.gif"; size=1070; creation-date="Fri, 02 Apr 2010 16:19:43 GMT"; modification-date="Fri, 02 Apr 2010 16:19:43 GMT" Content-ID: <[email protected]> Content-Transfer-Encoding: base64 R0lGODlhEAAQAPcAABxuHJzSlDymHGy2XHTKbITCdNTu1FyqTHTCXJTKhLTarCSKHEy2JHy6bJza lITKfFzCPEyWPHS+XHzCbJzSjFS+NLTirBx6HHzKdOz27GzCZJTOjCyWHKzWpHy2ZJTGhHS+VLzi (more base64 string here that I'm not going to paste) But when it finally prints the encoded mime string, this is a different string than I was expecting: encoded mime string: R0lGODlhEAAQAO+/vQAAHG4c77+90pQ877+9HGzvv71cdO+/vWzvv73vv71077+977+977+9XO+/vUx077+9XO+/vcqE77+92qwk77+9HEzvv70kfO+/vWzvv73alO+ Clearly different from the one that has its output in the part above. I'm not even sure what I'm looking at here, but when I try to load this as an image in a html page, it won't work. This is fairly frustrating for me, since all I want is a piece of the text that I'm already printing, but I'd rather not have to search through the mime string myself for the correct part, introducing all kinds of bugs.So I'd really prefer to use the Javamail library but could use some help on how to actually get that correct mime string.

    Read the article

  • Order of parts in SMTP multipart messages

    - by Chris
    Hi, I'd like to know how to build an SMTP multipart message in the correct order so that it will render correctly on the iPhone mail client (rendering correctly in GMail). I'm using Javamail to build up an email containing the following parts: A body part with content type "text/html; UTF-8" An embedded image attachment. A file attachment I am sending the mail via GMail SMTP (via SSL) and the mail is sent and rendered correctly using a GMail account, however, the mail does not render correctly on the iPhone mail client. On the iPhone mail client, the image is rendered before the "Before Image" text when it should be rendered afterwards. After the "Before Image" text there is an icon with a question mark (I assume it means it couldn't find the referenced CID). I'm not sure if this is a limitation of the iPhone mail client or a bug in my mail sending code (I strongly assume the latter). I think that perhaps the headers on my parts might by incorrect or perhaps I am providing the multiparts in the wrong order. I include the text of the received mail as output by gmail (which renders the file correc Message-ID: <3977333.1.1274154021787.JavaMail[email protected]> Subject: =?UTF-8?Q?Test_from_=E3=82=AF=E3=83=AA=E3=82=B9?= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_20870565.1274154021755" ------=_Part_0_20870565.1274154021755 Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-ID: <20100518124021763_368238_0> iVBORw0K ----- TRIMMED FOR CONCISENESS 6p1VVy4alAAAAABJRU5ErkJggg== ------=_Part_0_20870565.1274154021755 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <html><head><title>Employees Favourite Foods</title> <style> body { font: normal 8pt arial; } th { font: bold 8pt arial; white-space: nowrap; } td { font: normal 8pt arial; white-space: nowrap; } </style></head><body> Before Image<br><img src="cid:20100518124021763_368238_0"> After Image<br><table border="0"> <tr> <th colspan="4">Employees Favourite Foods</th> </tr> <tr> <th align="left">Name</th><th align="left">Age</th><th align="left">Tel.No</th><th align="left">Fav.Food</th> </tr> <tr style="background-color:#e0e0e0"> <td>Chris</td><td>34</td><td>555-123-4567</td><td>Pancakes</td> </tr> </table></body></html> ------=_Part_0_20870565.1274154021755 Content-Type: text/plain; charset=us-ascii; name=textfile.txt Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=textfile.txt This is a textfile with numbers counting from one to ten beneath this line: one two three four five six seven eight nine ten(no trailing carriage return) ------=_Part_0_20870565.1274154021755-- Even if you can't assist me with this, I would appreciate it if any members of the forum could forward me a (non-personal) mail that includes inline images (not external hyperlinked images though). I just need to find a working sample then I can move past this. Thanks, Chris.

    Read the article

  • Maven problem with invalid jar file which is actually html

    - by fei
    i'm running into a problem in my maven build recently, that it downloads a jar file for the javamail-1.4.jar or something, but it turns out the file is not a real jar file, it's actually a html with a link to where to get the correct jar. it seems to be the repo has changed for that. but in my maven setting everything is supposely to go to our internal repo, i don't know how did that happen. but anyways, more importantly, how do i fix this problem so that it will download the correct jar file on a fresh install? thanks!

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >