Results 1 to 10 of 10
- 10-05-2011, 03:57 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Urgent, please respond with haste
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-05-2011, 04:10 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Urgent, please respond with haste
responding for duty!
Seriously though, leave URGENT, deadline, etc out of post titles.
- 10-05-2011, 04:28 AM #3
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
Re: Urgent, please respond with haste
Maybe you should ask your email host (MSN) for the server, or an even better idea would be to ask an email server question, on an email forum.
- 10-05-2011, 04:37 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Re: Urgent, please respond with haste
my appology for double post.
Last edited by Bagzli; 10-05-2011 at 04:41 AM.
- 10-05-2011, 04:40 AM #5
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Re: Urgent, please respond with haste
ok
and
its called java mail so hey I figured, why not ask on java forums? And there is really no need to get angry over such a small thing, If i have it in wrong section just tell me and I'll repost in the proper one.
- 10-05-2011, 04:43 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Urgent, please respond with haste
I hope no anger was meant. It's perfectly acceptable to post it here if it is indeed java mail. If, however; it's very email server related you may want to ask it somewhere more specific. That being said, I'm sure one of the people here can help you out (unfortunately I am not one of them in this matter).
- 10-05-2011, 04:44 AM #7
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Re: Urgent, please respond with haste
it was meant for the other guy and thanks for the header tips.
- 10-05-2011, 04:52 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Urgent, please respond with haste
- 10-05-2011, 04:53 AM #9
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
Re: Urgent, please respond with haste
Sorry, i had no intention of coming across as angry.
- 10-05-2011, 05:16 AM #10
Re: Urgent, please respond with haste
This is Tested:
Java Code:// Author : Engr. Md. Kamruzzaman // Email : kamrul.kzaman@gmail.com import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import java.util.Properties; // Class Declaration public class SendMail { public SendMail(){ } // Send Method // hostIp : Mail server IP address, //from : Mail from address (e.g xyz@domain.com) //to : Mail to address (e.g abc@domain.com) //cc : Mail CC address, bcc : mail to bcc address //subject : mail subject, //body : mail body, //filename attachment file name including path public boolean send(String hostIp,String from,String to,String cc,String bcc,String subject,String body,String filename) { String smtpHost=hostIp; String host=""; boolean status=false; try { Properties properties = System.getProperties (); host=smtpHost; properties.put("mail.smtp.host", host); Session session = Session.getInstance(properties, null); MimeMessage message = new MimeMessage(session); if(from!=null) { Address fromAddress = new InternetAddress(from); message.setFrom(fromAddress); } // Parse and set the recipient addresses if(to!=null) { Address[] toAddresses = InternetAddress.parse(to); message.setRecipients(Message.RecipientType.TO,toAddresses); } if(cc!=null) { Address[] ccAddresses = InternetAddress.parse(cc); message.setRecipients(Message.RecipientType.CC,ccAddresses); } if(bcc!=null) { Address[] bccAddresses = InternetAddress.parse(bcc); message.setRecipients(Message.RecipientType.BCC,bccAddresses); } // Set the subject and Body message.setSubject(subject); // Attach file with message if(filename.equals(null)||filename.equals("")) { /* MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body);*/ BodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(body, "text/html"); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); // add the Multipart to the message message.setContent(mp); } else { File file = new File(filename); if(file.exists()) { /*MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body);*/ BodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(body, "text/html"); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(filename); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message message.setContent(mp); } else { /* MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body); */ BodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(body, "text/html"); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); // add the Multipart to the message message.setContent(mp); } } // send the message Transport.send(message); status =true; }catch (AddressException e){ status = false; System.out.println("Address field found corrupted."); }catch (SendFailedException e){ status = false; System.out.println("Unknown SMTP host: "+host); }catch (MessagingException e) { status = false; System.out.println("Could not connect to SMTP host:"+host); }catch (Exception e) { status = false; System.out.println("Could not connect to SMTP host:"+host); } return status; } //test by this public static void main(String[] args) { SendMail sendmail = new SendMail(); boolean t=sendmail.send(mail_server_IP,"mailto:mailfrom@domain.com,mailto@domain.com,"",'',"Subject","body","c://abc.jpeg"); System.out.print(t); } }
Similar Threads
-
[URGENT]SHA Encryption System...need urgent helps
By java_idiot in forum New To JavaReplies: 6Last Post: 05-02-2010, 10:04 AM -
Serial port - send command respond
By boss-tech in forum Java AppletsReplies: 0Last Post: 07-23-2009, 12:53 PM -
I need Help Urgent..
By vidhyaprakash85 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-18-2009, 06:49 AM -
Urgent Help!!
By Winniee in forum New To JavaReplies: 5Last Post: 02-17-2009, 03:32 AM -
Very Urgent
By nehaa in forum AWT / SwingReplies: 6Last Post: 01-22-2009, 08:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks