Info2Mail

<< Click to display Table of Contents >>

Navigation:  Interfaces >

Info2Mail

Sending Cordaware bestinformed-Infos as E-Mail

 

The integrated Info2Mail interface allows you to send Infos as E-Mails.

 

For sending Infos as E-Mail you will have to set up E-Mail Filters which are built similar to a regular filter. When addressing an Info to this filter, the Infoserver will distribute the E-Mail stop the designated recipients by using the defined method.

 

In order to create your own Info2Mail filter please follow these steps:

 

1.) Create a filter which you want to use for Info2Mail

 

2.) Now choose the type "info2Mail" and the operator "script.is_info2mail" "is not empty"

 

Info2Mail_Filter

 

3.) The following is a script example which can be used for the creation of an Info2mail Filter.

 


-module(info2mail).

-export([main/1]).

 

main(_) ->

 

  %%%-------------------------------------------------------------------

  %%% CONFIGURATION

  %%%-------------------------------------------------------------------

 

  %% Enter the SMTP server of your provider here.

  Relay = "",

 

  %% Enter the port used to communicate with the SMTP server.

  Port = 25,

 

  %% Enter your login name here, which you use to register with your mail provider.

  UsernameOrEmail = "",

 

  %% Enter your password into the Cordaware bestinformed password vault.

  %% Then enter here the alias of your password that you have defined in the password vault.

  PasswordAlias = "",

 

  %% Specify here whether you need to authenticate with your mail provider:

  %%  * true  = Authentication required

  %%  * false = Authentication not required

  Auth = false,

 

  %% Set your desired encryption method here. The following values are possible:

  %%  * tls  = TLS encryption

  %%  * ssl  = SSL encryption

  %%  * none = No encryption

  Secure = tls,

 

  %% Enter the mail addresses of the desired recipients here.

  %% Multiple recipients can be specified in a comma-separated list.

  %% Make sure that NO comma is added after the last recipient!

  To = [

    "recipient_1@mail.com",

    "recipient_2@mail.com"

  ],

 

  %% Enter the mail address of the sender here.

  From = "sender@mail.com",

 

  %% Enter the subject of the mail here.

  Subject = "New Info",

 

  %% Resend the email after editing the info

  SentInfoOnEdit = true,

 

  %%%-------------------------------------------------------------------

  %%% INTERNAL FUNCTIONS

  %%%-------------------------------------------------------------------

    Mail = [

      {relay, Relay},

      {port, Port},

      {username, UsernameOrEmail},

      {password, PasswordAlias},

      {auth, Auth},

      {secure, Secure},

      {sslopts, [{verify, verify_none}]},

      {to, To},

      {from, From},

      {debug, fun(TO) -> best_script:debug_msg("Send email to: ~p", [TO]) end},

      {subject, Subject},

      {body, best_script:info()},

      {content_type, html}

    ],

    ShouldSend = case SentInfoOnEdit of

        true -> not (bi_gv(<<"historie">>, best_script:infodoc()) or best_script:canceled());

        false -> not best_script:i2m_already_sent(best_script:info_id())

    end,

    if ShouldSend -> best_script:sendmail(Mail, []); true -> ok end,

  true.

%%-------------------------------------------------------------------

%% HELPER FUNCTIONS

%%-------------------------------------------------------------------

 

bi_gv(Key, Values) -> proplists:get_value(Key, Values).

bi_gv(Key, Values, Default) -> bi_default(bi_gv(Key, Values), Default).

 

bi_default(undefined, Default) -> Default;

bi_default(Value, _) -> Value.

 


Please note:

 

If you use encryption via SSL/TLS and the certificate was not issued to the hostname of the machine, you must also set the setting “{sslopts, [{verify, verify_none}]}” from All-In-One version 6.4 onwards to enable a connection.

 

If you have created the script, you can edit and save it as you like.

 

 

4.) After saving the filter, you can select the filter you just created as the recipient in the Infoeditor.

 


Please note: If your mail provider requires a password for authentication, the password must be stored in a password safe. You can enter the name of the password safe in the example script.

 

 

Configuring Info2Mail via Microsoft SMTP (OAuth2)

 

You can use the Microsoft SMTP server for Info2Mail by utilizing OAuth2. This requires a specific script and a password safe.

 

For the configuration, you will need the following information, which must be entered into the script as strings (within the quotation marks):

 

Sender email address: (e.g., user@tenant.onmicrosoft.com)

Microsoft Tenant ID

Client App ID

Microsoft Client Secret: This will be stored in a new password safe. The script will reference the name of this safe.

 

Setup:

1.Create a password safe containing your Microsoft Client Secret.

 

2.Create the Info2Mail filter according to the existing instructions.

 

3.Use the script below and insert your specific data at the marked locations.

 


-module(ouath2_info2mail).

-export([main/1]).

 

main(_Doc) ->

 

  %%%-------------------------------------------------------------------

  %%% CONFIGURATION

  %%%-------------------------------------------------------------------

 

  %% Enter your Microsoft Tenant ID here.

  TenantID = "TenantID of Microsoft",

 

  %% Enter the ID of your registered application (Client App ID) here.

  ClientID = "Client App ID",

 

  %% Enter the name of the safe containing the Microsoft Secret here.

  ClientSecretTresor = "MicrosoftClientSecret",

 

  %% Enter the SMTP server here.

  Relay = "smtp.office365.com",

 

  %% Enter the communication port here.

  Port = 587,

 

  %% Enter your login name (email) for the tenant here.

  Username = "user@tenant.onmicrosoft.com",

 

  %% Enter the email addresses of the desired recipients here.

  To = [

    "recipient_1@mail.com",

    "recipient_2@mail.com"

  ],

 

  %% Enter the sender name and email here.

  From = "User <user@tenant.onmicrosoft.com>",

 

  %% Enter the email subject here.

  Subject = "Your Subject",

 

  %%%-------------------------------------------------------------------

  %%% INTERNAL FUNCTIONS

  %%%-------------------------------------------------------------------

 

  Res = best_script:httprequest(post, 

          {"https://login.microsoftonline.com/"++TenantID++"/oauth2/v2.0/token", [], 

          "application/x-www-form-urlencoded",

          "client_id=" ++ ClientID ++ "&client_secret=%secret%&scope=https%3A%2F%2Foutlook.office365.com%2F.default&grant_type=client_credentials"

          }, [], [{password,[{ClientSecretTresor,"%secret%"}]}]),

          

  % best_script:debug_msg("result of http is ~p",[Res]),  

  

  case Res of

    {ok, {{_, 200, _ReasonPhrase}, _RespHeaders, RespBody}} ->

        {Json} = best_script:json_decode(list_to_binary(RespBody)),

        AccessTokenTemp = proplists:get_value(<<"access_token">>, Json),

        AccessToken = <<"xoauth_",AccessTokenTemp/binary>>,

        

        Mail = [

            {relay, Relay},

            {port, Port},

            {username, Username},

            {password, AccessToken},

            {auth, true},

            {secure, tls},

            {send_always, true},

            {to, To},

            {debug, fun(Type,TO) -> best_script:debug_msg("Send email ~p to: ~p",[Type,TO]) end},

            {from, From},

            {subject, Subject},

            {sslopts, [{verify, verify_none}]},

            {body, best_script:info()},

            {content_type, html}

        ],

        

        best_script:sendmail(Mail,[]);

    _Else ->

        false

  end,

 

  true.