Following program to send email to gmail accounts not working..help me.

after deployment the following program leads to this error
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 39sm1006913yxd.27
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<html>
<body>
<%
String name=request.getParameter("name");
String from=request.getParameter("mail");
String message1=request.getParameter("msg");
try{  
String toAddress="[email protected]";
String fromAddress=from;
String fromName=name;
String messageSubject="feedback";     
String messageBody1=message1;
          Properties props=new Properties();          
          props.put("mail.smtp.host","smtp.gmail.com");          
          Session session1=Session.getDefaultInstance(props,null);     
          Message message=new MimeMessage(session1);
          message.setFrom(new InternetAddress( fromAddress, fromName));
          message.setRecipient(Message.RecipientType.TO,new InternetAddress( toAddress));
          message.setSubject( messageSubject);
          message.setText( messageBody1);
          message.setSentDate(new Date());
          Transport.send(message);
catch(Exception e)
{out.println(e);
%>
</body>
</html>

When I run the code
<html>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.Transport.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.sun.mail.smtp.*" %>
<body>
<%
try{  
String to="[email protected]";
String from="[email protected]";
String subject="feedback";     
String message="Hello";               
     Properties props = new Properties();
          props.put("mail.smtp.host","smtp.gmail.com");
          props.put("mail.smtp.auth", "true");
          props.put("mail.smtp.starttls.enable", "true");
          Session session1 = Session.getDefaultInstance(props);
          session1.setDebug(false);
          // create a message
          MimeMessage msg = new MimeMessage(session1);
          if ( from == null ) from = "[email protected]";
          InternetAddress fromAddress = new InternetAddress(from);
          msg.setFrom(fromAddress);
          InternetAddress[] toAddresses = InternetAddress.parse(to);
          msg.setRecipients(Message.RecipientType.TO, toAddresses);
          msg.setSubject(subject);
          msg.setHeader("X-Mailer", "smtpsend");
          msg.setSentDate(new java.util.Date());
          msg.setText(message);
          SMTPTransport t = (SMTPTransport)session1.getTransport("smtps");
              try {
               t.connect("smtp.gmail.com", "[email protected]", "password");
               t.sendMessage(msg, msg.getAllRecipients());
         finally {
          out.println("Response: " + t.getLastServerResponse());
               t.close();
catch(Exception e)
{out.println(e);
%>
</body>
</html>I got the following exception
Response: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Similar Messages

  • Outgoing email from gmail account not working

    emails sent from gmail on iphone dont work.
    this is really getting annoying.
    Its a brand new phone with fresh 2.1 firmware and new email accounts.
    Also im using imap with gmail.
    I checked with 2 gmail accounts and same thing along with the other threads regarding not receiving emails at regular intervals unless its plugged in.
    Message was edited by: crosswire

    waiting for a test
    Just wondering if i should wipe the iphone completely n start from scratch with new fw2.1
    dont think it would make much diff
    any opinions

  • Can't Send Emails From Gmail account on iPhone

    Everytime I try to send an email from my gmail account on my phone it says "The connection to the outgoing server "smtp.gmail.com" failed. Additional Outgoing Mail Servers can be configired in Settings>Mail,Contacts,Calendars."

    Can you try to set up your email account again? Delete it from Genereal > Mail, Contacts,... > click on your Gmail > Delete Account and set it up from start.
    http://iphone-and-i.blogspot.com/2012/01/how-to-set-up-email-account-on-iphone.h tml

  • Mail won t send emails with gmail account.

    Mail app was working perfectly and suddenly it stopped working
    All i have configured is my gmail account with IMAP, it receives the mails perfectly but i cant get any mail to leave my outbox. I simply get the timeout error with the try again or edit settings message.
    I rechecked and recreated the outgoing mail server with the settings from google, and it still happens.
    I tried rebuilding the outbox as i read on these forums that it might help, but it didnt.
    What else can I do?
    thank you
    Charles .

    Hi.
    You could try moving the preference file to the trash.
    The file is called com.apple.mail.plist
    and can be found in the following folder: username -> library -> preferences

  • Sending Email from Multiple Accounts, not just one.

    I have 3 email accounts set up on my iPhone, 1 Gmail, 2 two POP accounts.
    For example if I get an email from Gmail, I check it in the phone and hit reply it goes out, from Gmail.
    If I view an email in another POP account (NONGMAIL) and hit reply, the reply is sent from my GMail address. What gives?
    If you reply to a message from another account shouldn't it go from that account? I don't want to be responding to work emails with my Gmail address.
    Does the iPhone only support 1 account to send email? I tried changing the default account that did nothing using the mail client. Anyone else have this issue.

    I'm having my issue. I have a gmail and an IMAP account set up on my phone.
    When I have my default mail set to my gmail account, and I go into either inbox of my iphone's email application and send to a third email address, the emails appear to be coming from my gmail account.
    When I change my default mail to be my IMAP account, the email STILL appears to be coming from my gmail account, no matter which account I send from.
    The punchline is that, with either account set to default and sending from either account, the copy that I BCC to myself ends up being sent to BOTH email accounts.
    Any idea what's going on?

  • After update, cannot send email via any accounts! Please help!

    First of all, thank you for reading my thread.
    After updating few days ago, I cannot send any email via any acounts. I have .mac email and yahoo email. But I still can receive emails. I have checked message borad, it said "Some members experienced difficulty sending .Mac Mail via computer email applications from 3:30 am to 6 am Pacific Time. Normal service has been restored." But mine hasn't!!! It has been almost a week!!
    The erro message says "cannot send email using this mail server, please choose one of the following server and retry again"
    My english is not very good, I hope you understand my question and any help would be appreciated, thank you again.

    Thank you very much for your reply!
    This is what I got:
    PING smtp.mac.com (17.250.248.45): 56 data bytes
    --- smtp.mac.com ping statistics ---
    10 packets transmitted, 0 packets received, 100% packet loss
    PING mail.mac.com (17.250.248.152): 56 data bytes
    --- mail.mac.com ping statistics ---
    10 packets transmitted, 0 packets received, 100% packet loss
    It seems the problem is the server, but it has been many days, I don't think apple haven't had notice this.
    What should I do next?

  • Sending emails in mail does not work

    I have a problem with Apple Mail i can receive Emails but i can't send emails it says: cannot send message using smtp.live.com server. the server works on my iPhone. so is there a diffrent server for Mail on the Mac? it is a hotmail account POP3 server. is the outgoing server diffrent from the iPhone version?

    You'll get more targeted and faster answers by posting in the Leopard forums. This forum link with tag:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.5_leopard#/?tagSet=1 017
    ahould let you see all the Mail posts made by 10.5 users.

  • 'Send email to group' is not working

    I have just made a group in address book. As far as I can tell, I have made it in exactly the same way as all my other groups. However, when I right click on the group name, and choose 'send email to group', it opens a window with nothing in the To: field. I've tried restarting the app, restarting the computer, and even creating the group again, but still it doesn't work.
    All other groups made before this still work fine: when I choose 'send email to group' the To: field is filled with recipients's addresses.
    This is a real problem for me as I use this feature all the time. I'd appreciate any help.

    Seems to be working now. I don't know what was wrong before.

  • Cannot send email using gmail account

    Within the last month or so, sending mail from my gmail id in Thunderbird fails. Receiving works fine. I'm running windows 7 on a desktop.
    Status says - 'connected to smtp.gmail.com...'
    Error message is - 'Sending of message failed. The message could not be sent because the connection to SMTP server smtp.gmail.com timed out. Try again or contact your network administrator.'
    Server settings are:
    Server type - pop mail server
    Server name - smtp.gmail.com
    port - 995
    connection security - ssl/tls
    authentication method - normal password
    outgoing server settings - for my id - I have smtp.gmail.com

    Not sure why you have port 995. That is the Inbound port for POP email server. Last time I checked the SMTP ports are 587 or 465.

  • I am getting hundreds of emails from community please tell how to stop them.  I have already changed my email preferences it did not work help

    Getting hundreds of emails from community forum.  Have tried changing email preferences.  HELP PLEASE

    no it isn´t.
    I already had these settings but still received 100+ mails a day with lots of topics I never even had read...
    now I deactivated ALL notifications.

  • HT1694 Can't send emails through Hotmail account

    This just started.  I can receive emails, but can't send emails through Hotmail account. iPhone says I need to check my settings (password).  I have correct password in settings.  Any help?

    Hello reedstrom,
    Sorry to hear you are not able to send emails from your Hotmail account.  Sending emails is a very important feature of the iPhone, and the fourth section in the following tutorial has steps for checking your Outgoing Mail Server settings. 
    Setting up Mail
    http://www.apple.com/support/iphone/assistant/mail/#section_4
    I hope this helps!
    Best,
    Sheila M.

  • Problem sending emails with gmail on iPhone

    Everytime I send email with gmail on my iPhone. The message doesn't show up in the folder sent messages (only on the server). This never happens with my iCloud account or when I send email from Mail in osx. Does anyone have a solution for this?

    Take a look at this link, https://discussions.apple.com/message/21206691#21206691

  • Cant send mail to gmail account

    hii,
    i have developed a code to send email messages with attach file.i can easily use it sending to my official email but cant send it to gmail account. the error says:
    italics Invalid Addresses 550 5.6.4 Unable to relay for [email protected]+italics+

    http://java.sun.com/products/javamail/FAQ.html#norelay

  • Cannot send email from 3 accounts Mac Pro

    My brand new Mac Pro cannot send email using Gmail, Shaw, or iCloud.  At times I can send a simple test message, other times I cannot send.  It seems the more data in the email, it for sure cannot be sent.  The sent messages get stuck in the Out Box.  Full green lights, no red lights in the connection diagnostics window.  Any help in this regard will be much appreciated.

    thank you for your reply, I did this with the same problem.  Turns out that I went to FAQ section and went to the "Sharing" section of "system preferences"  and changed my computer name by removing all spaces and apostrophe where it lists my computer name under Mac Book Pro, and problem solved.

  • Cannot send email from pop account when in 3G, will send in WIFI

    I cannot send email from pop account when in 3G, will send in WIFI.
    I thought it was the SMTP server first.. but when i config my WIFI, suddenly the emails that i tried to send, left my outbox and sent.
    Any idea's

    The SMTP server you are using with Wi-Fi would be the outgoing server of your internet service provider... this is likely why that's working.
    SMTP servers specific to a ISP would not work on the 3G network. You would probably need another SMTP server. One from your cell provider?

Maybe you are looking for

  • Safari no longer shows the browser when I open it. No magnifying glass. Where has it gone?

    My Father-in-law used my computer yesterday and now when I open Safari it no longer shows the magnifying glass/browser. I have tried to restore from backup and reinstalling but these do not work. It seems as though he did something to turn disable it

  • VGA display powered off

    iMac in classroom, with VGA display connected for occaisional use.  When I open a new finder window it opens on this 'second display' which is not on, and thus invisible to me.  I want the window to appear on the iMac desktop, but it uses the externa

  • Same parameter-map used on 2 different classes

    Greetings, If the same parameter-map (type connection or http) is used on two different policy-map classes, will that create a conflict in how traffic for each of serverfarms uses persistence or inactivity timeout (script 1)? Should we create a diffe

  • FI table for Report painter

    Which table I will take to create FI report in Report Painter ? Please help me.. Thanks & Regards, Ananda

  • Itinerant onsite working - managing mail accounts

    Hi Hope you've had a good weekend... thanks for stopping by. I have a fair number of different email accounts... [email protected], [email protected], [email protected] The thing I crave is that when I pitch up at the offices of one-client.com for a