![]()
|
||||||
How to send e-mails by Servlet/JSP with JavaMail API / File Upload Servlet/JSP by multipart/form-data / Select Time Zone (TimeZone) / Object Serialization
Free source code example for how to send e-mail by Servlet with JavaMail API. You can upload files by multipart/form-data and attache them to the e-mail. You can send e-mails at the scheduled time.
When you specify when the e-mail will be sent, the available TimeZones will be listed and you can select the favorite Time Zone among them.
The e-mail is stored into the SQL table by the Object Serialization.
Once the e-mail is queued, the back-ground Thread will select it at the scheduled time and send it.
If you'd like to send e-mails immediately... :If you'd like to send e-mails immediately, there is another Java API for you. It is much simpler API, and a few lines of code will be enough for your JSP/Servlet to send e-mails with the file attachment. Download the source code example:
Related Pages:
|
||||||
About this free source code example:
This free source code example shows how to send the e-mail at the scheduled time from Servlets/JSP with JavaMail API. It also includes the file upload Servlet/JSP by multipart/form-data. The binary contents of the uploaded file will be attached to the e-mail along with the file name and the Content-Type. You can specify when the e-mail will be sent by your favorite Time Zone (Java TimeZone object).
OOP MimeParser is responsible for parsing the multipart/form-data. After it parses the InputStream of the multipart/form-data of the uploaded files,
In addition, OOP MimeParser can restrict the mime-types (or Content-Types) of the file to be uploaded. If the user tries to upload the file with another mime-type, OOP MimeParser throws the exception. Again, in this case, the example Servlet/JSP can catch the exception and show the appropriate message. When the user edit the new e-mail, s/he should fill all the fields on the CGI form. To check the availabilities of all the required data, the example Servlet/JSP uses OOP FormGenerator. By the help of this Java API, a few lines of code are enough to check the validities of the data from the CGI form.
Save the uploaded file on the file system:
You may want to save the uploaded file on the file system, rather than getting its binary contents directly.
Don't worry. OOP MimeParser also implements the methods for this case.
This API parses the InputStream of the multipart/form-data and saves the uploaded file under the specific directory.
If you have an interest in this feature, please look into another source code example.
How to start the back-ground Thread:
The queued e-mail will be selected by the back-ground Thread at its scheduled time and will be sent to the SMTP server. You may wonder how such a Thread can be started/stoped from your Servlet/JSP.
Download example source codeThe source code of this example is available at the link below: This example depends on the following Java APIs: These Java APIs are available at Java API Shop by OOP-Research. Once you entered in this online shop, you can add as many items as you like to your shopping cart. To download the 30 days FREE trial version, please click Try button for the intended API.Optionally, you can use: along with OOP MailScheduler. OOP PooledStatement implements the pooling mechanism for the PreparedStatement and ensures the Thread Safety of your web application.
InstallationIn addition, OOP MailScheduler requires the following APIs:
In this distribution, all the source files are pre-compiled into:
Because the installation of OOP MailScheduler depends on how it gets the JDBC Connection, the above file structure may differ with your strategy. For example,
Only if you use OOP MailScheduler along with OOP PooledStatement, you need to edit:
with:
NOTE for oop_util_3_x.jar: If you have the older version oop_util_3_x.jar, please replace it with the new one. In other words, please be sure to find only the latest version of oop_util_3_x.jar under WEB-INF/lib directory. NOTE for JBuilder: Please add all the jar files above to Required Libraries of your project.
|
|
|||||
|
Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries. |
||||||
|
ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved. |
||||||