Problems when sending an email through a servlet

Hi I have a servlet trying to send an email to an address given.. but the servlet does not respond at all, it doesn's throw any exception nor displays any message, anything I hope you can help, this is the DoGet method I have in the servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
System.out.println("In doGet method");
StringBuffer body=null;
try {           
body = setBodyMessage(request);
sendmail(body);
out.println("<table align=center cols= 2 border=0 width=100% height=100% >");
out.println("<tr><td>");
out.println("<div align=center><b><font face=Arial, Helvetica, align=center sans-serif size=4 color='red'> The Change request was sent </font></b></div></td></tr></table>");
catch(NullPointerException e){
e.printStackTrace();
out.println(e.toString());
out.println(e.getMessage());
catch (Exception e) {
e.printStackTrace();
System.err.println(e.toString());
System.out.println(e.toString());
finally{
out.close();
The function setBodyMessage, sets a properly e-mail body message to be sent by the parameters that come from a previous form page.
I have this sendmail method defined as follow:
public void sendmail(StringBuffer mailBody){
String email = "[email protected]";
try{
PrintStream outmail;
SmtpClient send = new SmtpClient("nyschx06psge.sch.ge.com");
send.from("[email protected]");
send.to(email);
outmail = send.startMessage();
outmail.println("From: [email protected]");
outmail.println("To: " + email);
outmail.println("Subject: Welcome");
outmail.println(mailBody.toString());
outmail.flush();
outmail.close();
send.closeServer();
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
I try it out in a jsp page and the code works but I need it running in a servlet. Can anyone help me please?, thanks in advance.
Regards.

Are you able to print the value of StringBuffer body before calling the sendmail method?

Similar Messages

  • HAVE A PROBLEM WHEN SENDING AN EMAIL IT STATES IT DOES NOT ALLOW RELAYING

    HAVE A PROBLEM WHEN SENDING AN EMAIL IT STATES IT DOES NOT ALLOW RELAYING

    You have either entered the wrong SMTP server info or they have blocked the sending of e-mails from outside their network. That message indicates that you are not permitted to send through that server from the network you are using to connect.
    Contact them again. There is no magic that will allow you to bypass this.

  • Problem when send an email with mail client!

    Hi!
    My mail server have MTA front end and Message Store back end with version:
    ./imsimta version
    Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)
    libimta.so 7u2-7.02 64bit (built 02:28:03, Apr 16 2009)
    Using /opt/sun/comms/messaging64/config/imta.cnf (compiled)
    SunOS SMSG 5.10 Generic_139556-08 i86pc i386 i86pcMy users and I are having problem following: Send an email very slow, mail client is connected to front end but mail is not delivered, after that, I stop and resend this email several times then it is can delivered. While the mail was not send, i can telnet to front end with port 25. My users and I are using Thunderbird and Microsoft Outlook. What is problem on my mail server ?
    I see time on MTA front end and Message Store are not synchronized, maybe this could be the problem?
    Thanks!

    NguyenPhuc wrote:
    Are you using any kind of MTA spam filter plugin?I removed plugin spam filter, now on MTA server don't have plugin spam or virus !Are you saying you did have a spam filter plugin enabled (if so which one(s)) and you have just disabled it?
    Are you receiving an excessive number of emails?No, total of number messages in my mailbox is about 1000 emails.I meant is the MTA receiving a large number of emails -- i.e. do you see a lot of emails coming in (mail.log_current)?
    Also try the following and see where the delay in accepting emails occurs:
    telnet <mta> 25
    mail from: [email protected]
    rcpt to: [email protected]
    data
    Subject: test email
    To: [email protected]
    From: [email protected]
    body
    .e.g.
    -bash-3.00# telnet server 25
    Trying 10.15.10.33...
    Connected to server.aus.sun.com.
    Escape character is '^]'.
    220 server.aus.sun.com -- Server ESMTP (Sun Java(tm) System Messaging Server 7u3-16.01 64bit (built Apr  6 2010))
    mail from: [email protected]
    250-2.5.0 No HELO/EHLO seen; continuing anyway, [10.15.10.33].
    250 2.5.0 Address Ok.
    rcpt to: [email protected]
    250 2.1.5 [email protected] OK.
    data
    354 Enter mail, end with a single ".".
    To: [email protected]
    From: [email protected]
    body
    250 2.5.0 Ok, envelope id [email protected]
    quit
    221 2.3.0 Bye received. Goodbye.
    Connection to server.aus.sun.com closed by foreign host.Regards,
    Shane.

  • When sending an email through windows live I get an error message from WebKit2WebProcess.exe

    Hi,
    Every time when I try and send an email from windows live I get an error message from WebKit2WebProcess.exe.
    Not sure if I deactivate this from Windows live whether I will compromise my security.
    Any advice would be helpful.
    Thanks,
    Becky

    Thank you Matt. I'm sure this will be frustrating ...but the more I think about this problem there more info I have to share. The emails I write that do not get sent do end up in my "sent" folder but never reach the recipient. And, most perplexing, the issue/problem is sporadic. It was coming and going before I switched over to the SSL/TLS option in T-bird. And...since the switch it has reappeared and disappeared. I have made zero changes other than the above mentioned. I did get a security update today for T-bird perhaps this will help?
    I read your link, thank you.
    I obviously don't understand how these systems work. I'm baffled how an issue like this can come and go...

  • Can't attach some files when sending an email through Safari (via Gmail)

    I'm trying to send an email to myself, and I can't seem to attach files that were created using iWork programs (Pages, Numbers etc.) How can I get Safari/Gmail to allow me to email these files?

    I can't seem to attach files that were created using iWork programs (Pages, Numbers etc.)
    These are not files; they are folders that appear as files to the user. To email them to anyone you must create an archive (.zip file) of them and email that archive to the recipient.
    Mulder

  • I have a problem when sending an email. It takes minutes just to put in the receivers address. More Below:

    I can put the first letter of the address instantly, but I cannot put the rest of the address in after the first letter. It takes minutes just to put in the full address. What is wrong? Address for answer is [email protected]

    Something is wrong
    We could not activate your account. Please make sure that you have clicked the correct link in your email or typed in the correct address.
    And my new post is not on the forum. It's titled "how do I get rid of the blank space at the bottom of the new Firefox menu?"

  • After updating to the new ios5 with my 4S , no wifi connection (at home), problem when sending or receiving email

    After updating to the new ios5 with my 4S, no wifi connection and problem when sending or receiving email. I had no issue before the update... I am very disappointed

    Did you already try to reset your network settings in Settings/General/Reset?

  • Sending an email from a servlet

    Hi Guys,
    Im trying to send an email from a servlet. I am using the following code:
    IMPORTING LIBRARIES
    import java.util.*;
    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    //importing JDBC
    import java.sql.*;
    //email
    import java.net.*;
    import java.text.*; // Used for date formatting.
    BEGIN CLASS
    public class Email3 extends HttpServlet
         private Socket smtpSocket = null;
         private DataOutputStream os = null;
         private DataInputStream is = null;
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    PrintWriter out = res.getWriter();
    OUTPUT TAGS FOR WEBPAGE
         out.println("<html>");
    out.println("<head>");
    out.println("<title>FYP</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<center>");
    send email
              //Date dDate = new Date();
              //DateFormat dFormat = _
         //DateFormat.getDateInstance(DateFormat.FULL,Locale.US);
         String m_sHostName="localhost";
         int m_iPort=25;
              try
              { // Open port to server
                   smtpSocket = new Socket(m_sHostName, m_iPort);
                   os = new DataOutputStream(smtpSocket.getOutputStream());
                   is = new DataInputStream(smtpSocket.getInputStream());
                   if(smtpSocket != null && os != null && is != null)
                   { // Connection was made.  Socket is ready for use.
                        out.println("Connection was made. Socket is ready for use.");
                        //[ Code to send email will be placed in here. ]
                        try
                             {   os.writeBytes("HELLO\r\n");
                             // You will add the email address that the server
                             // you are using know you as.
                             os.writeBytes("MAIL From: <[email protected]>\r\n");
                             // Who the email is going to.
                             os.writeBytes("RCPT To: <[email protected]>\r\n");
                             //IF you want to send a CC then you will have to add this
                             os.writeBytes("RCPT Cc: <[email protected]>\r\n");
                             // Now we are ready to add the message and the
                             // header of the email to be sent out.
                             os.writeBytes("DATA\r\n");
                             os.writeBytes("X-Mailer: Via Java\r\n");
                             //os.writeBytes("DATE: " + dFormat.format(dDate) + "\r\n");
                             os.writeBytes("From: Me <[email protected]>\r\n");
                             os.writeBytes("To: YOU <[email protected]>\r\n");
                             //Again if you want to send a CC then add this.
                             os.writeBytes("Cc: CCDUDE <[email protected]>\r\n");
                             //Here you can now add a BCC to the message as well
                             //os.writeBytes("RCPT Bcc: BCCDude<[email protected]>\r\n");
                             String sMessage = "Your subjectline.";
                             os.writeBytes("Subject: Your subjectline here\r\n");
                             os.writeBytes(sMessage + "\r\n");
                             os.writeBytes("\r\n.\r\n");
                             os.writeBytes("QUIT\r\n");
                             // Now send the email off and check the server reply.
                             // Was an OK is reached you are complete.
                             String responseline;
                             while((responseline = is.readLine())!=null)
                             {  // System.out.println(responseline);
                             out.println("responseline= "+responseline+"<br>");
                             if(responseline.indexOf("Ok") != -1)
                                  //out.println("responseline"+responseline);
                             break;
                             catch(Exception e)
                             {  System.out.println("Cannot send email as an error occurred.");
                                  out.println("Cannot send email as an error occurred.");
              catch(Exception e)
              { System.out.println("Host " + m_sHostName + "unknown"); }
              out.println("</center>");
              out.println("</body>");
              out.println("</html>");
              out.close();
    }//end class
    it compiles fine, the connection was made ok but im not receiving the email. When the email is sent off the server reply does not seem to be Ok, as the print statement i tried there is not being executed. When i print the content of my responseline= variable before the if statement i get the following:
    Connection was made. Socket is ready for use. responseline= 220 centaur.elec.qmul.ac.uk ESMTP Exim 3.16 #2 Thu, 09 Jan 2003 15:54:34 +0000
    responseline= 500 Command unrecognized
    responseline= 250 is syntactically correct
    responseline= 550 relaying to prohibited by administrator
    responseline= 500 Command unrecognized
    responseline= 503 No recipient(s).
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 221 Closing connection. Good bye.
    Can anyone help?
    Is there an easier way to send an email from a servlet?
    Thanks
    tzaf

    It's not a matter of "easier way" to send mail from servlet...you are missing a crucial element in your code: authorization to send mail. You need something like this (some of which you have already so note what is different):
            Properties properties = new Properties();
            properties.put("mail.smtp.host", String3 );
            properties.put("mail.smtp.dsn.notify", "SUCCESS" );
            properties.put("mail.smtp.host", "mailservernamegoeshere");
            properties.put("mail.smtp.auth", "true");
            MyAuthenticator auth = new MyAuthenticator();
            auth.setUser("user whos account you want to use goes here");
            auth.setPassword("user password goes here");
            Session session = Session.getDefaultInstance( properties,auth );Here is the auth class:
    class MyAuthenticator extends Authenticator {
       protected String m_strUser     = null;
       protected String m_strPassword = null;
       protected PasswordAuthentication getPasswordAuthentication()  {
          return new PasswordAuthentication(m_strUser,m_strPassword);
       public void setUser(String strUser)  {
          m_strUser = strUser;
       public void setPassword(String strPassword)  {
          m_strPassword = strPassword;

  • Using JProgressBar when sending an email

    Good day to all! How can I use the JProgressBar to monitor progress when
    sending an email? I am using the Email package by Jakarta Commons.
    Somehow, I need my application to display progress since the send( )
    function takes a considerable amount of time to complete.
    Regards...

    >
    I Want to learn how to send email . Could you please
    tell me how to send email. and also give me some
    sample Code . so that i can Understand
    Sure. :) I just used a simple-To-Use API of Jakarta Commons Email, which is
    built on Java Mail. Their main site may start you off through simple examples.
    Go to this page: http://jakarta.apache.org/commons/email/userguide.html

  • Major problem when trying to email a picture from my Iphone 4

    Hi,
    I encounter a very strange problem when sending pictures from my iphone 4 via mail.
    The problem is as followed,i go to Photos->Camera Roll->Choose a picture that i took->Email Photo->Send->Small\Medium\Large\Actual Size (Never mind what i am choosing they all have the same affect).
    I am getting the email with the Picture Inline ( not as attachment),The picture is shown distorted , no metter what i do and with what mail client i am using (Gmail\Hotmail\My Enterprise exchange mail), i still get the same behavior.
    I got 2 friends with the same phone as i do Iphone 4 with version 4.2.1,When they are sending a picture in the same procedure that i use, the picture is shown as an attachment in the mail and without any problems at all.( it can be seen both in the sent items , and in the inbox at the received side).
    What is the problem , it made me frustrater i cannot send pictures ,This a must for me ,I dont want to use any 3rd party app or something like that.....
    Thanks in advance for all the helpers..
    Tomcat

    All photo attachments received or sent with the iPhone's Mail app appear inline or viewed in place within the body of the message when viewed with the iPhone's Mail app which is the same with the Mail.app on a Mac. A photo attachment that appears inline or viewed in place does not mean the photo was not sent as a true attachment to the message. A photo attached to a message with the iPhone's Mail app is sent as a true attachment to the message. How an inline or viewed in place attachment appears on the recipient's end depends on the recipient's email client. If the recipient's email client does not support viewing an attached photo inline or viewed in place within the body of the message, the attached file must be manually selected and opened to viewed.
    I am getting the email with the Picture Inline ( not as attachment),The picture is shown distorted , no metter what i do and with what mail client i am using (Gmail\Hotmail\My Enterprise exchange mail), i still get the same behavior.
    With which email client?

  • Why I can't  send my email through my Ipad 3?

    I don't know what to do. everytime I send my email through my ipad 3 , It said because of outsider server but I think it is not correct . cos my friend can send it but me not so what shoud i do?

    Sann Raksmey wrote:
    why when I connect my Ipad3 to my Window Computer it does not charge? I mean my ipad not charge like when I connect it with other App Computer at Apple Store?
    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • Sending an email through JavaMail

    Hi
    I am trying to send an email through JavaMail, the jsp page which is sending the mail is called testmail.jsp. Code snippet:
    try
    InternetAddress toAddress = new (InternetAddress"xxxxxxxx","xxx");
    InternetAddress fromAddress = new InternetAddress("xxxxxxx","xxxxxx");
    Properties props = new Properties();
    props.put("mail.smtp.host", "xxxxxxxx");
    Session mailsession = Session.getDefaultInstance(props, null);
    Message msg = new MimeMessage(mailsession);
    msg.addRecipient(Message.RecipientType.TO, toAddress);
    msg.setSubject("A Simple E-mail Message!");
    msg.setFrom(fromAddress);
    msg.setText("Hi\rThis message has been sent from a JSP page.\nBye\rTest");
    Transport.send(msg);
    %>
    <b>An e-mail has been sent.</b>
    <%
    catch (Exception e)
    e.printStackTrace();
    When i send the email to my own email address(on the same domain where the actual testmail.jsp is hosted) my mail is being sent successfully. BUT when i try sending to eg. a hotmail address I just get a blank page with no errors (from Tomcat) and no mail is sent.
    PLEASE HELP. Is it something to do with the protocol or am I doing something wrong
    THANKS LODES
    sabcarina

    Basically, it's fine. The only thing I could see (other than adding imports, etc.) was that there was an extra open parenthesis in the first InternetAddress declaration. This is my complete JSP, which worked fine for me:<%@ page import="javax.mail.*" %>
    <%@ page import="javax.mail.internet.*" %>
    <%@ page import="java.util.*" %>
    <%
    try {
       InternetAddress toAddress = new InternetAddress("[email protected]","Bill Gates");
       InternetAddress fromAddress = new InternetAddress("[email protected]","Hotmail");
       Properties props = new Properties();
       props.put("mail.smtp.host", "smtp.server.address");
       Session mailsession = Session.getDefaultInstance(props, null);
       Message msg = new MimeMessage(mailsession);
       msg.addRecipient(Message.RecipientType.TO, toAddress);
       msg.setSubject("A Simple E-mail Message!");
       msg.setFrom(fromAddress);
       msg.setText("Hi\rThis message has been sent from a JSP page.\nBye\rTest");
       Transport.send(msg);
       %>
          <b>An e-mail has been sent.</b>
       <%
    } catch (Exception e) {
       e.printStackTrace();
    %>Bob

  • When sending an email to multiply recipiants, using address autocompletion, all the address boxes convert to the name in the first box

    I use Thunderbird for my email. When sending an email to multiple recipients, I use autocompletion from my local address book. When I select an additional recipient, the name initially appears correctly in the address box. Each time I drop down to add another recipient, the names in each box all revert to the name in the first box. I've used Thunderbird for 2 years and this just started today. Also, the cursor and names in the address box appear now in red instead of black. Hopefully you can solve this problem.
    Thank you,
    bradoc

    There are some evil bugs in the current version of Thunderbird. You may find it works better if you click with the mouse, or move down with the arrow keys and click or use tab. IIRC, there's an issue with use of the Enter key. Or maybe the other way round ; please experiment. It's one of those frustrating bugs that seems to affect everyone but me.
    You can download older versions here:
    https://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/
    I believe 31.2.0 is free of this particular issue. 24.6 seems to be a popular choice for those who dislike recent changes in the Composition window UI.

  • Getting errors when sending/receiving email

    Hi there I have only just updated to Windows 10 from 8.1 nd am able to receive mails On outlook 2013 but continually get the following error message 
    Task '[email protected] - Sending' reported error (0x800CCC13) : 'Cannot connect to the network. Verify your network connection or modem.' I have tried everything but cant get it fixed can someone help Thanks Bryan

    Same thing here Fresh install of windows 10 and Outlook 2013 Receiving emails but getting the same error message when sending and emails stuck in Outbox. Tried all available options in account settings but it doesnt make any difference. Strangley enough though when initially setting up the mail account it sends its test email no problems. Installed Outlook 2010 to see if there was any difference but the same thing happens.

  • Can LabVIEW send an email through Microsoft Exchange server without an account set up in Outlook?

    I've found sample code that shows how to send email through Outlook using LabVIEW.  On any computer I log into on our network, my profile loads and I have access to the exchange server through Outlook so the code works.
    However, I am developing a program that will run on a lab computer with a generic PC login that is shared among everyone in the lab.  Exchange server/outlook is not set up for the generic user.
    Is it possible to have labVIEW send an email through the exchange server with a server name, username, and password coded into the executable?

    You would need to send a standard SMTP message via Exchange. The Exchange server will likely require authentication, so you won't be able to use the built-in SMTP VIs, as they do not support authentication. If you're on Windows you can use .NET (see this example), or use the OpenG SMTP VIs.

Maybe you are looking for

  • Error by sending a mail

    Hi Everybody, Can someone tell me what i m doing wrong in the following code , to send email: REPORT  ZTESTADEL2. TABLES: ekko. PARAMETERS: p_email   TYPE somlreci1-receiver                                   DEFAULT '[email protected]'. TYPES: BEGIN OF

  • All Emails Sent to Verizon Email Addresses Are Blocked - Please Help

    Hello, Email messages that our company sends to Verizon recipients are being blocked by the anti-spam system. I have copied a sample failure message below. I have submitted whitelist requests several times, but get automated messages in return saying

  • Appleworks from Classic to X ???

    Hello, I've just got a Macbook Pro Leopard, how can I transfer my Appleworks 5.04 application documents from my iMac 9.2.2 desktop to my Macbook Pro? I have already tried using Firewire, External Harddrive (non-bootable),OS9 Install CD, iMac System I

  • Keychain Problem with Safari

    I have been having a problem with autofill and Safari that I have tracked to Keychain. If I enable autofill and press edit in the window of the prefs of safari then rather than getting all the websites that keychain has access to I get a swod and I h

  • Slow Safari with a Twist

    I've read through the "Slow Safari" posts, but haven't seen a problem exactly like mine...my Safari runs fast sometimes, slow other times, usually when I'm entering some kind of form. For example, no problem getting to Apple Support-->Discussions-->S