Skip to main content

Posts

Showing posts with the label JavaMail

Sending email by JavaMail API

The  JavaMail  API is not part of core Java SE, but an optional extension. In addition, it is required in Java Enterprise Edition. The JavaMail packages can be accessed in two ways : by placing  j2ee.jar  in the classpath or, by placing both  mail.jar  and  activation.jar  in the classpath The  javax.mail  API uses a properties file for reading server names and related configuration. These settings will override any system defaults. Alternatively, the configuration can be set directly in code, using the JavaMail API. *********Sample code*************** import java.io.File; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; /** * Handles sending email and attachments. */ public final class Emailer {   ...