title: Sending email in Java by using database
body: <p>I am currently doing a project where I am required to send an email to the specific address taken from database. However, the column "email" in database does not actually contain emails, but names instead. So in database there are full names in russian language like </p>
  
  <p>"Иванов Александр" which is "Ivanov Alexandr". So when I type this name in the outlook it automatically finds his email: AIvanov@domainname.com. But in my java code when I use name "Иванов Александр" i keep getting error.</p>
  
  <p>Here is my java code</p>
  
  <pre><code>File[] listOfFiles = outDir.listFiles();
      if (outDir.isDirectory()) {
          if (outDir.list().length &gt; 0) {
              for (File file : listOfFiles) {
                      Session session_m = Session.getDefaultInstance(props, null);
                      MimeMessage message = new MimeMessage(session_m);
                      message.setFrom (new InternetAddress("mmm@domainname.com", "mmm@domainname.com"));
                      InternetAddress i = new InternetAddress("\""+email+"\"", false);
                      message.addRecipient(Message.RecipientType.TO, i);
                      message.setSubject("test");
                      message.setText("test");
                      message.setHeader("Content-Type","text/plain;charset=windows-1251");
  
                      MimeBodyPart mbp1 = new MimeBodyPart();
                      FileDataSource fds = new FileDataSource(file);
                      mbp1.setDataHandler(new DataHandler(fds));
                      mbp1.setFileName(fds.getName());
  
                      Multipart mp = new MimeMultipart();
                      mp.addBodyPart(mbp1);
  
                      System.out.println("[EmailHandler] Attaching the following file to email: " + fds.getName());
                      message.setContent(mp);
  
                      SMTPTransport t = (SMTPTransport)session_m.getTransport("smtp");
                      t.connect("mail.domainname.com", "main@domainname.com", null);
                      System.out.println("[EmailHandler] Sending email... ");
                      t.sendMessage(message, message.getAllRecipients());
                      file.delete();
                      Thread.sleep(3000);
                  }
              } else {
                  System.out.println("[EmailHandler] Folder " + outDir.getName() + " is empty... nothing to attach");
              }
          } else {
              System.out.println("Folder not found... Check the path");
          }
  </code></pre>
  
  <p>In this code the String <strong>email</strong> is Иванов Александр. </p>
  
  <p>And I kept getting this error</p>
  
  <p>javax.mail.internet.AddressException: Local address contains control or whitespace in string ``Иванов Александр''</p>
  
  <p>So would like to know the ways I can make this string go through.</p>
  
  <p>Thank you.</p>