Results 1 to 3 of 3
Thread: Need help with sending a text
- 10-05-2011, 04:37 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
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:
directly taken from: JavaMail API documentationJava 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); }
Now here is the error I get when I run it.
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.Java Code:send failed, exception: javax.mail.MessagingException: Unknown SMTP host: my-mail-server; nested exception is: java.net.UnknownHostException: my-mail-server
- 10-06-2011, 03:40 PM #2
Member
- Join Date
- Feb 2011
- Location
- Ahmedabad
- Posts
- 36
- Rep Power
- 0
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-.gif)
- 10-07-2011, 07:31 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
Sending Text File --- Server-To-Client
By nigamsir in forum NetworkingReplies: 1Last Post: 03-08-2010, 03:45 PM -
Sending text to a web page
By shyameni in forum Advanced JavaReplies: 2Last Post: 10-08-2009, 07:14 AM -
Sending text to a web page
By shyameni in forum Advanced JavaReplies: 0Last Post: 10-07-2009, 06:38 PM -
Sending text to printer
By Java Tip in forum Java TipReplies: 1Last Post: 05-25-2009, 06:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks