title: Unable to send mail with attached file using Javamail API
body: <p>I am trying to send an email with these codes but there's an error.</p>
  
  <pre><code>import java.util.*;
  import javax.mail.*;
  import javax.activation.*;
  import javax.mail.internet.*;
  
  public class SendEmail {
  
    public static void main(String args[]) throws Exception {
    String host = "localhost";
    String from = "myemail@hotmail.com";
    String to = "recipientemail@hotmail.com";
  
    Properties properties = System.getProperties();
  
    properties.setProperty("mail.smtp.host", host);
  
    Session session = Session.getDefaultInstance(properties);
  
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("JavaMail Attachment");
  
    BodyPart messageBodyPart = new MimeBodyPart();
  
    messageBodyPart.setText("hi");
  
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
  
    //attachment
    messageBodyPart = new MimeBodyPart();
    String filename = "C:/Users/ME/Desktop/file.txt";
    DataSource source = new FileDataSource(filename);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
  
    message.setContent(multipart);
  
    Transport.send(message);
    System.out.println("Msg Send ....");
    }
  }
  </code></pre>
  
  <p>I got a 'HTTP Status 404' error and the description is "The requested resource () is not available."<br>
  May i know why and how to solve this?<br>
  Sorry as i'm a beginner in programming and java</p>
  
  <p>Thanks in advance!</p>