- Add blastengine.jar in your Java project path like
app/libs
. - Include jar file in your project. eg.)
implementation(fileTree(dir: 'libs', include: ['blastengine.jar']))
in your gradle.build.
import jp.blastengine.BEClient;
import jp.blastengine.BETransaction;
import jp.blastengine.BEBulk;
import jp.blastengine.BEMailAddress;
import jp.blastengine.BEError;
BEClient.initialize("YOUR_USER_NAME", "YOUR_API_KEY");
BETransaction transaction = new BETransaction();
transaction.subject ="Test mail from blastengine";
transaction.text = "Mail body";
transaction.html = "<h1>Hello, from blastengine</h1>";
BEMailAddress fromAddress = new BEMailAddress("info@example.com", "Admin");
transaction.setFrom(fromAddress);
transaction.addTo("user@example.jp");
try {
Integer deliveryId = transaction.send();
System.out.println(deliveryId);
} catch (BEError e) {
System.out.println(e.getMessage());
}
BEBulk bulk = new BEBulk();
bulk.subject ="Test mail from blastengine";
bulk.text = "Mail body";
bulk.html = "<h1>Hello, from blastengine __name__</h1>";
BEMailAddress fromAddress = new BEMailAddress("info@example.com", "Admin");
bulk.setFrom(fromAddress);
Integer deliveryId = bulk.register();
Map<String, String> map = new HashMap<>();
map.put("name", "User 1");
bulk.addTo("user1@moongift.jp", map);
map.put("name", "User 2");
bulk.addTo("user2@moongift.jp", map);
bulk.update();
// Immediately
bulk.send();
// Reserve
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 1);
bulk.send(cal.getTime());
bulk.importFile("path/to/csv"); // Import if there is no error in the CSV file. Only import action.
bulk.importFile("path/to/csv", true); // Skip error line and import valid line. And only import action.
BEJob job = bulk.importFile("path/to/csv", true, true); // Skip error line and import valid line, and send email immediately.
System.out.println(job.totalCount); // Total number of recipients
System.out.println(job.successCount); // Number of successful recipients
System.out.println(job.failedCount); // Number of failed recipients
List<Map<String, String>> errors = job.errors(); // Get error details
if (errors != null) {
System.out.println(errors);
}
MIT License.