Results 1 to 3 of 3
  1. #1
    Bagzli is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default Need help with sending a text

    Hi, i'm on a deadline here so i was wondering if somebody can point me in right direction.

    Here is my code:
    Java Code:
    Properties props = new Properties();
                    props.put("mail.smtp.host", "my-mail-server");
                    props.put("mail.from", "me@example.com");
                    Session session = Session.getInstance(props, null);
    
                    try {
                        MimeMessage msg = new MimeMessage(session);
                        msg.setFrom();
                        msg.setRecipients(Message.RecipientType.TO,
                                          "example@msn.com");
                        msg.setSubject("JavaMail hello world example");
                        msg.setSentDate(new Date());
                        msg.setText("Hello, world!\n");
                        Transport.send(msg);
                    } catch (MessagingException mex) {
                        out.println("send failed, exception: " + mex);
                    }
    directly taken from: JavaMail API documentation

    Now here is the error I get when I run it.
    Java Code:
    send failed, exception: javax.mail.MessagingException: Unknown SMTP host: my-mail-server; nested exception is: java.net.UnknownHostException: my-mail-server
    how do i find out the SMTP Host and my-mail-server? I want to use example@msn.com but if MSN is not compatible i'm willing to get a new email address with a compatible host.

  2. #2
    Join Date
    Feb 2011
    Location
    Ahmedabad
    Posts
    36
    Rep Power
    0

    Default Re: Need help with sending a text

    Hi Bagzli

    what is my-mail-server?
    you can try

    props.put("mail.smtp.host", "smtp.gmail.com");


    you can also study following code for it

    Java 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");
     
    		Session session = Session.getDefaultInstance(props,
    			new javax.mail.Authenticator() {
    				protected PasswordAuthentication getPasswordAuthentication() {
    					return new PasswordAuthentication("username","password");
    				}
    			});
     
    		try {
     
    			Message message = new MimeMessage(session);
    			message.setFrom(new InternetAddress("from@no-spam.com"));
    			message.setRecipients(Message.RecipientType.TO,
    					InternetAddress.parse("to@no-spam.com"));
    			message.setSubject("Testing Subject");
    			message.setText("Dear Mail Crawler," +
    					"\n\n No spam to my email, please!");
     
    			Transport.send(message);
     
    			System.out.println("Done");
     
    		} catch (MessagingException e) {
    			throw new RuntimeException(e);
    		}
    Hemant Metalia
    cool

  3. #3
    Bagzli is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default Re: Need help with sending a text

    thanks a lot, it really helped me out

Similar Threads

  1. Replies: 0
    Last Post: 12-09-2010, 05:56 PM
  2. Sending Text File --- Server-To-Client
    By nigamsir in forum Networking
    Replies: 1
    Last Post: 03-08-2010, 03:45 PM
  3. Sending text to a web page
    By shyameni in forum Advanced Java
    Replies: 2
    Last Post: 10-08-2009, 07:14 AM
  4. Sending text to a web page
    By shyameni in forum Advanced Java
    Replies: 0
    Last Post: 10-07-2009, 06:38 PM
  5. Sending text to printer
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 05-25-2009, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •