Send email from j2me through servlet

Hi people,
i hope you can help me because i am new in network programming.
I am trying to send email from j2me to googlemail account I have 2 classes EmailMidlet (which has been tested with wireless Toolkit 2.5.2 and it works) and the second class is the servlet-class named EmailServlet:
when i call the EmailServlet, i get on the console:
Server: 220 mx.google.com ESMTP g28sm19313024fkg.21
Server: 250 mx.google.com at your service
this is the code of my EmailServlet
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class EmailServlet extends HttpServlet {
   public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException {
      System.out.println("____emailservlet.doPost");
      response.setContentType("text/plain");
      PrintWriter out = response.getWriter();
      System.out.println("______________________________");
      out.println();
      String to = request.getParameter("to");
      System.out.println("____________________________to" + to);
      String subject = request.getParameter("subject");
      String msg = request.getParameter("msg");
      // construct an instance of EmailSender
      System.out.println("servlet_to" + to);
      send("[email protected]", to, subject, msg);
      out.println("mail sent....");
   public void send(String from, String to, String subject, String msg) {
      Socket smtpSocket = null;
      DataOutputStream os = null;
      DataInputStream is = null;
      try {
         smtpSocket = new Socket("smtp.googlemail.com", 25);
         os = new DataOutputStream(smtpSocket.getOutputStream());
         is = new DataInputStream(smtpSocket.getInputStream());
      } catch (UnknownHostException e) {
         System.err.println("Don't know about host: hostname");
      } catch (IOException e) {
         System.err
               .println("Couldn't get I/O for the connection to: hostname");
      if (smtpSocket != null && os != null && is != null) {
         try {
            os.writeBytes("HELO there" + "\r\n");
            os.writeBytes("MAIL FROM: " + from + "\r\n");
            os.writeBytes("RCPT TO: " + to + "\r\n");
            os.writeBytes("DATA\r\n");
            os.writeBytes("Date: " + new Date() + "\r\n"); // stamp the msg
                                                // with date
            os.writeBytes("From: " + from + "\r\n");
            os.writeBytes("To: " + to + "\r\n");
            os.writeBytes("Subject: " + subject + "\r\n");
            os.writeBytes(msg + "\r\n"); // message body
            os.writeBytes(".\r\n");
            os.writeBytes("QUIT\r\n");
            // debugging
            String responseLine;
            while ((responseLine = is.readLine()) != null) {
               System.out.println("Server: " + responseLine);
               if (responseLine.indexOf("delivery") != -1) {
                  break;
            os.close();
            is.close();
            smtpSocket.close();
         } catch (UnknownHostException e) {
            System.err.println("Trying to connect to unknown host: " + e);
         } catch (IOException e) {
            System.err.println("IOException: " + e);
   } 1.when i print "to" in EmailServlet also:
  String to = request.getParameter("to");
      System.out.println("____________________________to" + to);  it show null on the console :confused:
2. ist this right in case of googlemail.com?
  smtpSocket = new Socket("smtp.googlemail.com", 25);  I would be very grateful if somebody can help me.

jackofall
Please don't post in old threads that are long dead. When you have a question, please start a topic of your own. Feel free to provide a link to an old thread if relevant.
I'm locking this thread now.
db

Similar Messages

  • Sending email from Oracle through Lotus Domino Server

    Hi,
    I would like to know whether it is possible to send an email from Oracle through a Lotus Domino Server(acting as mail server). If yes, please provide me with the details.
    Thanks in advance

    Have a look at the database UTL_SMTP package

  • Cannot send email from Mail through .mac account

    I have recently opened a .mac account and started using the email service. It works fine online however I am having difficulty sending messages through the Mail application in Tiger.
    Whenever I attempt to send a message, a dialog box appears saying "Cannot send message using the server smtp.mac.com".
    I have tried looking at the setting in preferences. I have deleted and .mac a/c setting in Mail and re-set them up, all the problem persists.
    Please help!

    Hello David.
    Who is your ISP used for connecting to the internet and are you accessing an email account snd SMTP server in Mail provided by your ISP?
    If so, can you send messages with the email account and SMTP server provided by your ISP?
    Most, if not all ISPs now block the use of SMTP servers that are outside of their network (or not provided by the ISP used for connecting to the internet) on Port 25 which is the standard port used for SMTP servers. Some ISPs allow the use of an authenticated SMTP server only (such as the .Mac SMTP server) that is outside of their network on Port 25 but some block its use regardless.
    These restrictions are part of an overall effort to prevent spam emanating from the ISP's domain.
    Something to try.
    Go to Mail > Preferences > Accounts and under the Account Information tab for your .Mac account preferences at the SMTP server selection, select the Server Settings below for the .Mac SMTP server.
    Enter 587 in place of 25 in the Server Port field and when finished, select OK to save the changed setting.
    Test if this resolves the problem.
    If not and you are accessing an email account and SMTP server in Mail that is provided by your ISP used for connecting to the internet, select/use your ISP's SMTP server to send mail with your .Mac account which is invisible to all recipients.

  • TS3899 When sending email from the Mail App or through other Apps, my default From: address will change when I enter a To: address.  This sometimes leads me to send the email from the wrong outgoing email account.  It is frustrating and poor design.

    When sending email from the Mail App or through other Apps on my iPad, my default From: address will change when I enter a To: address.  This sometimes leads me to send the email from the wrong outgoing email account.  It is frustrating and poor design, especially since I had already checked the From: address.
    iPad 4 running iOS 8.1.3

    3rd party email addresses have to be deleted on every synmced mac product, although I have 1and1.co.uk and my imac updatetes the mails in that account from mac mail.
    Yahoo etc is a 2 step deleting process but good to get your emails pushed when on the go.
    LJ
    http://www.facebook.com/The.Cowboy.Party

  • Cannot send email from within iPhoto

    Using OX X 10.7.5 cannot send email from within iPhoto.  I get this error message: "Your email did not go through because the server did not reply."
    If I change the preference to use email, everything goes fine but I lose the formatting feature.

    iPhoto Menu ->
    Preferences ->
    Accounts ->
    Delete and recreate your email settings.
    Alternatively, use Apple's Mail for the job. It has Templates too - and more of them. Check out the Stationery...

  • Cannot Send Email From iMac

    I cannot send email from any of my accounts via any of the asssociated servers, however I can receive mail through any of my accounts and servers. I haven't touched any of the preference setttings for any of the accounts so am really in the dark as to where to start to look for problems. I am using OS X 10.8.3.
    Andy

    Have you read for possible solutions over in the "More Like This" thread over here?-----------------------> 

  • Unable to send emails from any Apple devices

    Since BT made the changes to Yahoo mail i have had problems with sending emails from my ipad and iphone (IOS8). The only way that i can successfully send an email is to log onto my laptop and send from a windows platform. I have checked all of the settings which are correct and im stumped. I am continuing to receive mail so why cant i send mail? I have contacted the BT customer support to be told that they are not trained on ios platforms so they cant help! pretty gobsmacked with that reposnse tbh, anyone have any ideas?

    You may want to delete the email account and try setting it up again. Once you have deleted it, re-start your phone.
    Set it up manually and do not use the wizard.
    It is best to go through settings >mail contacts, calendars > add account… > don’t choose the BT or BTYahoo option, tap the ‘other’ option from the bottom of the list > Add Mail Account and enter the following details:
    Name – it can be anything you want, but usually your real name is preferable
    Address – your full BT Internet email address
    Password – your email account password
    Description – this can be used if you have more than one email account on the device but put something like ‘work’ or  ‘BT Internet
    Press “Next” and allow the verification (this may take a few minutes)
    On the next screen it will want you to input incoming and outgoing mail server details:
    Tap ‘IMAP’ at the top,
    Incoming mail server settings:
    Host name: mail.btinternet.com
    Username: your full  BT Internet email address
    Password: your email account password
    Outgoing mail server settings:
    Host name: mail.btinternet.com
    Username: your full BT Internet email address
    Password: your email account password
    Press ‘next’
    Slide the notes and mail to be ‘on’ and press ‘save’ in the top-right
    Check your email on the device and see if it is working. Try sending yourself a message and see if it arrives. If messages are not able to send do the following:
    Additional setting changes
    Go to Settings > Mail, Contacts, Calendars > tap your BT email account > a window will appear, tap on your email address > scroll down to the bottom of the window and tap where it says ‘SMTP’ > tap the primary server (which should be mail.btinternet.com) >make sure the following is on or enabled:
    ‘Use SSL’ should be ‘ON’
    Authentication should be ‘password’
    Server port should be ‘465’
    Press ‘done’ in the top-right

  • I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    As you haven't told us who your email provider is, no.
    There isn't an SMTP server for Greece - it is either provided by your email provider, or the Internet provider you are connected through.

  • Can't send email from Outlook with parentheses in address

    I can't send email from Outlook 2007 through my WRT400N when Outlook displays the address with parentheses as in this example: Firstname Lastname ([email protected])
    I can send if the address is in this form: Firstname Lastname <[email protected]>
    I have tested with the ISP and nothing gets through the router when the problem occurs. When I bypass the router, both forms of address will send correctly. This problem is perfectly reproducible. My router is brand new, but the problem did not show up for about a week after installation. OS is Win7. Any ideas? Thanks.
    -JimW
    Solved!
    Go to Solution.

    Try to forward the port 443 to 447 on the router.Check this link.

  • How do I fix Mail in Snow Leopard where I cannot send emails from my account to another account I've set up in Mail, but the reverse works fine?

    I have a problem with Mail in Snow Leopard in that I cannot set up two email accounts for myself and my wife with the same ISP and have them operate properly.  I've set up the accounts in strict accordance with my ISP's instructions for setting up email accounts on Mac Mail but I cannot send an email from my account to my wife's without a drop-down message appearing that Mail 'cannot send the email from this server.  Please edit the server list'.  No amount of tweaking appears to work.  Applecare consultants have so far been unable to get it to work and a recent visit to the local Genius Bar in the Apple Store was fruitless also.  My ISP's help line was unable to solve the problem even with a supervisor level consultant.  The ISP concluded it was some kind of 'bug' in Mail.
    I could send emails from my wife's account to mine, but not vice versa; I could send emails to other addresees without any problem and I can send emails from my account to my wife's using the ISP's webmail.
    Does anyone please have a solution to my problem?  At the moment we're operating one account (mine) on my Macbook and my wife's is set up on her iPad2.  As we prefer to use the Macbook for storage and (using Time Machine) for back-up of our data, the two accounts on separate machines is a nuisance.
    Another factor is that I prefer to control when I download emails and set my preferences accordingly.  One of the so-called 'fixes' that were tried wound up downloading emails regardless of settings, even after removing my wife's account; the matter was remedied only after I had removed all accounts form Mail and started afresh from scratch.

    You'll have to pardon my ignorance of some  computer terminology; I'm a retired manager and not a computer technician, hence my muddling up of client and server terminology.
    Re your comment about Port 339: I did qualify this with (?).  As I wrote, it all happened at lightining speed and the guy at the Genius Bar didn't bother explaining what he was doing.  Port designation contained 3s and 9s to the best of my recollection.
    That said, you seem to be spot on re setting up a 'dummy' client in Mail.  I set it up as you suggested and I can send to and receive from this client without a problem.  You appear to have identified the solution, notwithstanding the claims of the ISP's 'experts'.
    The next problem I have now is sorting out my wife's mailbox that is so troublesome whenever I set it up on Mail.
    All the other set-up advice to date yielded a similar result; inability to send from my account to her inbox.  Perhaps deleting her details from the account altogether and setting them up again from scratch may be the solution and I shall try that in due course.  The impediment that I have with this at the moment is that my ISP admits that it has 'a technical problem with its email servers' and some of its related web pages that prevent my doing this myself.  I will have to go through the telephone 'help' line and ask the technician to set it up at their end on my instructions.  This has some disadvantages in that I have to divulge the password to the account to the operator rather than keeping it anonymous by doing it on-line.   You may have solved the problem, but until I can successfully sort out a working mailbox for my wife i cannot definitively say so.
    Many thanks for your perseverance.  You've made more sense than anyone else so far and that deserves some points, surely?

  • TS4069 Can't send email from msn hotmail account on iPad or iPhone.

    Having trouble sending email from msn account on iPad 2 and iPhone 4. Can receive email just can't send it. Keeps saying the password or account name are incorrect when they are not. Can send and receive email when enter msn through safari.

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • When try send email from within iPhoto says password not recognised

    Hi,
    Trying to send email from withinn iPhoto always get message saying password not recognised even though set correct password email address within preferences in iPhoto. Believe this started when I upgraded to Lion.
    Lates Lion and iphoto updates downloaded
    Thanks
    Rick

    LarryHN I not understand your advice
    iPhoto preferences>
    Accounts>
    there I have Facebook and MobileMe as Accounts
    I tried adding new account and the only options (Apple related) offered are MobileMe and Email going
    EMail>
    again offers iCloud and mobileme
    using iCloud doesn't work i.e. the account sets up but still cannot send email through iPhoto
    I am registered with iCloud and it works fine in other applications
    I am reluctant to delete MobileMe from iPhoto since if I do so I will not be able to add it again I still have photos etc in my MobileMe iDisk which I will need to move somewhere else soon with demise of MobileMe
    Thakns for your advice

  • Can't send email from my iPhone...

    I am having problems sending email from my iPhone via my ISP and the ISP at work. I can send email through my personal domain from these places using my Mac laptop but not via the iPhone.
    Settings for the ISP should be SSL Off for both directions [incoming/outgoing] Authentication: Password and a strange config. for username:
    username+mydomain.com not just username and with the + symbol and not the @ I have entered the address correctly and I get Cannot Send Mail
    Sending contents of the message to the server failed.
    I have also tried:
    mail.mydomain.com:567 and :2525 and :465 and all return similar errors
    I should mention that I'm able to send mail to the phone and retrieve it successfully but not send from it.
    I've tried changing the Uses SSL for Outgoing and still no love. I have verified with my ISP that everything is correct and yet I am still unable to send email from the iPhone.
    Any suggestions or troubleshooting tips are greatly appreciated. My ISP is Site5 as well.

    Yeah, I read the Apple Tech Doc where it described how to add the port number so I tried 587, 465 and 2525 at the request of my hosting company's Forum userbase. All suggestions were attempted including converting the account on Site5 to IMAP and all tests resulted in no mail being sent and a cryptic error message with no useful details as to why the mail was not able to be delivered [like an error code or something useful]. I too am hoping that Apple says or does something about this in the near future.
    Usernames for my ISP must be formatted like so:
    username+domain.com
    I'm not sure if that's part of the problem but I've been successful at creating accounts for multiple mail clients including GyazMail for Mac, Thunderbird and several other mail clients but for the life of me, I can't get the iPhone to send a single bit of information via SMTP.
    Any assistance or news on this front would be greatly appreciated.
    iPhone, iMac G5, PowerBook G4 Mac OS X (10.4.10)

  • Can't send email from home

    I have a serious problem. My wife has a Mac Book Pro for work and she can send email at any location except from home. The error she is getting is
    Cannot send message using the server smtp.knology.net:(username)
    The server "smtp.knology.net" refuses to allow a connection on the default ports. Select a different outgoing mail server from the list below or click try later to leave the message in your outbox until it can be sent.
    I have BellSouth/AT&T DSL with a Westel Versalink 327W modem. The funny thing is our local library also has BellSouth DSL and she can send email from there. Like I said, the only place she can't send email is from our house.
    Thanks

    It is the BS/ATT system you are on. BS/ATT does not allow sending email to another domain from a Residential account. I had the same problem with my work email from home. All sent mail on port 25, I think it is, from a ATT Residential account must go through the ATT servers and or ATT/Yahoo.
    Have your wife check with the mail provider for an alternate sending port. My work mail servers used port 26 for POP and some other port for IMAP.
    EDIT:
    Right the Library has a Business Account. No restrictions on the Business ATT DSL.

  • How can I send email from my yahoo alias account in iPhone5 mail?

    How can I send email from my yahoo alias account in iPhone5 mail?
    I have 2 email accounts: [email protected] is an alias of [email protected]
    In my old iPhone3 I had these accounts set up so that I could send and receive email from both accounts. I did this using the following settings:
    ‘Other’ POP account info:
    Name: xyz
    Address: [email protected]
    Description: alias
    Incoming mail server:
    Host name: pop.mail.yahoo.com
    User name: [email protected]
    Password: password for yahoo account
    Server port: 995
    Outgoing mail server:
    SMTP: smtp.o2.co.uk (o2 is the name of my phone network)
    Server port: 25
    ‘Yahoo!’ account info:
    Name: xyz
    Address: [email protected]
    Password: password for yahoo account
    Description: Yahoo!
    Outgoing mail server:
    Primary server: Yahoo! SMTP server
    Server port: 465
    I’ve tried using the same settings in my new iPhone5, but it doesn’t work. I can receive mail to both accounts, and can send from the Yahoo account, but I cannot send mail from the alias account. When I try, it displays the message: “Cannot send mail. A copy has been placed in your Outbox. The recipient ‘[email protected]’ was rejected by the server”.
    I’ve tried to configure the POP alias account using combinations of ‘pop.mail.yahoo.com’, ‘pop.mail.yahoo.co.uk’, ‘apple.pop.mail.yahoo.co.uk’ and ‘apple.pop.mail.yahoo.com’, for the incoming host, and ‘smtp.o2.co.uk’, ‘smtp.mail.yahoo.com’, ‘smtp.mail.yahoo.co.uk’, ‘apple.smtp.mail.yahoo.com’ and ‘apple.smtp.mail.yahoo.co.uk’ for the outgoing mail server. None of these have worked.
    I’ve also tried setting it up using IMAP instead of POP without success. I tried configuring it using combinations of ‘imap.mail.yahoo.com’, ‘apple.imap.mail.yahoo.com’, ‘imap.mail.yahoo.co.uk’ and ‘apple.imap.mail.yahoo.co.uk’ for the incoming mail server and ‘smtp.o2.co.uk’, ‘smtp.mail.yahoo.com’, ‘smtp.mail.yahoo.co.uk’, ‘apple.smtp.mail.yahoo.com’ and ‘apple.smtp.mail.yahoo.co.uk’ for the outgoing mail server.
    Yahoo say that if I can't send Yahoo! Mail from my mail program, I may be accessing the Internet through an ISP that is blocking the SMTP port, and that if this is the case, I should try setting the SMTP port number to 587 when sending email via Yahoo!'s SMTP server. I don't think that this is the problem, but I tried it just to make sure - without success.
    I’ve also heard that the problem might have something to do with the SPF settings of my alias domain provider. I’m not too sure exactly what SPF settings are, or how to change them, but from what I can gather it seems unlikely that this is the problem given that I was able to send mail from my alias account on my old iPhone3.
    Any help much appreciated: how can I get my alias account to send emails in iPhone5 mail?
    Many thanks,
    Patrick

    A new development: I've tried sending emails from the alias several times over the past 24 hours, but in general I've deleted them if they haven't sent within about half an hour.
    However, one of the messages I left sitting in the outbox did send successfully in the end, but this took about an hour.
    So: perhaps my problem is not in fact that I am completely unable to send mail from my alias, but that I can only do so intermittently and extremely slowly, and by ignoring the "cannot send" message.
    Any help appreciated.

Maybe you are looking for

  • Dynamically loading images?One at a time :(

    codeworld....help...sos.....send in more troops....the titanic is sinking..... The problem: I am trying to load dynamic images in order without all of them attempting to load at once.... I have an array of images that I loop through depending on the

  • How to get ProxyEnable value from registry using Windows

    Hi, I have developed a webservice which check for a new version of software. Webservice works fine if the user does not use a proxy otherwise it raises an error "connection timeout....". I have found a lot of examples how to read a proxy from windows

  • Complex B/W picture to vectorize in simple form

    Hello, I have this complex black/white map of an island and would like to vectorize only the contour of the island. When I vectorize I choose B/W with a threshold of 15 pixels, and I clicked only contour. What I get is too precise. It also vectorize

  • Content for itunes in Canada

    My obvious question is are you waiting approval from the CRTC to use all the features the US Store has? If so when, looks like iphone functionality will also be hampered by borders. When you purchse an ipod, you take off the sticker displaying "Don't

  • Update freezes on old iTunes MP3s

    I just got my second 8GB nano in two days. The first one would not update - - it kept freezing during its update on particular songs. I decided the first ipod was defective and exchanged it for an identical one. I also have an ipod mini and an ipod 5