Giter VIP home page Giter VIP logo

wisdom-mailer's Introduction

Wisdom-Mailer

The Wisdom Mailer is an extension to Wisdom allowing application to send mails. A Wisdom extension to send mails using SMTP. It supports most of the mail services such as gmail.

The 0.5 version of Wisdom-Mailer requires Wisdom Framework 0.7.0+.

Installation

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>org.wisdom-framework</groupId>
    <artifactId>wisdom-mailer</artifactId>
    <!-- Use latest version here -->
    <version>0.5</version>
</dependency>

Or copy the jar file to the Wisdom's Application directory.

Configuration

The configuration can be done either from the application.conf file (src/main/configuration/application.conf) or using system properties. For all the properties described below you can use either way.

Property Description Default Value
mail.smtp.connection the connection type among NO_AUTH, SSL and TLS NO_AUTH
mail.smtp.host the SMTP server hostname (such as smtp.gmail.com) Mock Server
mail.smtp.port the STMP server port. Default is computed from to the connection type. 25 or 465
mail.smtp.from the default from address when it is not explicitly set No value
mail.smtp.from-name the sender name No value
mail.smtp.reply-to the 'reply-to' emails list No value
mail.smtp.username the account username when the service requires authentication required
mail.smtp.password the account password when the service requires authentication required
mail.tls.trustedservers (TLS) "*" or the list of trusted servers with invalid certificates empty
mail.smtp.debug enables the debug mode false

Examples

The following example is a correct configuration to use gmail:

# Mailer configuration
# ~~~~~~~~~~~~~~~~~~~~
mail.smtp.connection = SSL
mail.smtp.host = smtp.gmail.com
mail.smtp.port = 465
mail.smtp.from = [email protected]
mail.smtp.username = [email protected]
mail.smtp.password = pwd
#mail.smtp.debug = true

The username and password can be set using system properties (as well as all other properties). In this case the application.conf file would contain:

# Mailer configuration
# ~~~~~~~~~~~~~~~~~~~~
mail.smtp.connection = SSL
mail.smtp.host = smtp.gmail.com
mail.smtp.port = 465
mail.smtp.from = [email protected]
#mail.smtp.username = Not set here
#mail.smtp.password = Not set here
#mail.smtp.debug = true

Usage

Once configured you can use the mailer service as follows:

package org.wisdom.mailer;

import org.apache.felix.ipojo.annotations.Requires;
import org.ow2.chameleon.mail.Mail;
import org.ow2.chameleon.mail.MailSenderService;
import org.wisdom.api.DefaultController;
import org.wisdom.api.annotations.Controller;
import java.io.File;

@Controller
public class Example extends DefaultController {

    @Requires
    MailSenderService mailer;

    public void sendMail() throws Exception {
        // Send a simple mail
        mailer.send(new Mail()
                .to("[email protected]")
                .subject("Welcome to Wisdom")
                .body("Hello !"));

        // Send a mail with an attachment
        mailer.send(new Mail()
                .to("[email protected]")
                .subject("Wisdom Log")
                .body("Here is the current Wisdom Log file")
                .attach(new File("logs/wisdom.log")));
    }
}

The MailerSenderService is injected using the @Requires annotation, then you can use it directly.

wisdom-mailer's People

Contributors

cescoffier avatar magnet avatar jenf11 avatar

Watchers

James Cloos avatar Julien ETIEN avatar Damien Archaimbault avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.