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

    Default 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:
    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
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Urgent, please respond with haste

    responding for duty!

    Seriously though, leave URGENT, deadline, etc out of post titles.

  3. #3
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default 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.

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

    Default Re: Urgent, please respond with haste

    my appology for double post.
    Last edited by Bagzli; 10-05-2011 at 04:41 AM.

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

    Default 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.

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default 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).

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

    Default Re: Urgent, please respond with haste

    it was meant for the other guy and thanks for the header tips.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Urgent, please respond with haste

    Quote Originally Posted by Bagzli View Post
    it was meant for the other guy and thanks for the header tips.
    Hehe, I was actually aiming the 'I hope no anger was meant' at him.

  9. #9
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Urgent, please respond with haste

    Sorry, i had no intention of coming across as angry.

  10. #10
    kzaman's Avatar
    kzaman is offline Member
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    4
    Rep Power
    0

    Default 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

  1. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 10:04 AM
  2. Serial port - send command respond
    By boss-tech in forum Java Applets
    Replies: 0
    Last Post: 07-23-2009, 12:53 PM
  3. I need Help Urgent..
    By vidhyaprakash85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-18-2009, 06:49 AM
  4. Urgent Help!!
    By Winniee in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 03:32 AM
  5. Very Urgent
    By nehaa in forum AWT / Swing
    Replies: 6
    Last Post: 01-22-2009, 08:36 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
  •