AutomaticMailSendingFromCluster

From T2B Wiki
Revision as of 12:28, 26 August 2015 by Maintenance script (talk | contribs) (Created page with " === Why sending mail could fail ? === The command/library you use, and the arguments you give to this command/library, are important... First of all, if you specify an SM...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Why sending mail could fail ?

The command/library you use, and the arguments you give to this command/library, are important...

First of all, if you specify an SMTP server, you should always use mxin.vub.ac.be (or mxin.ulb.ac.be), and not smtp.vub.ac.be :

#dig @8.8.8.8 MX vub.ac.be
...
;; ANSWER SECTION:
vub.ac.be.		5058	IN	MX	10 mxin.vub.ac.be.
vub.ac.be.		5058	IN	MX	20 mxin.ulb.ac.be.
...

If you use commands like "mail", there is no need to specify the smtp server because this information is obtained from DNS.

Note that using "mail" or "sendmail" commands requires that postfix service is running :

service postfix start

Sending mails from scripts

These examples have been tested from a workernode (private network), and they worked :

Bash

#!/bin/bash

success() {
    echo "Sending mail from node19-1"
    sendmail -f toto@vub.ac.be -t <<End_of_sendmail
From: toto@vub.ac.be
To: toto@vub.ac.be
Subject: Sending a mail from node19-1

This is just a test message.
.
End_of_sendmail
    sleep 2
}

success

Perl

This script will work because ccq has been configured as a mail relay :

#!/usr/bin/perl -W


use MIME::Lite;
use Net::SMTP;



my $txt = "Don't pannic, it's just a test run on node19-1.\n";
send_mail($txt);

sub send_mail {

    my $from_address = 'toto@vub.ac.be';
    my $to_address = 'toto@vub.ac.be';
    my $mail_host = 'ccq.wn.iihe.ac.be';

    my $subject = "[TEST] Keep calm : test mail sent from a node";
    my $message_body = shift;

    $msg = MIME::Lite->new (
        From => $from_address,
        To => $to_address,
        Subject => $subject,
        Type =>'multipart/mixed'
        ) or die "Error creating multipart container: $!\n";

    $msg->attach (
        Type => 'TEXT',
        Data => $message_body
        ) or die "Error adding the text message part: $!\n";


{| border=1 class="simple"
! die "Cannot send email\n";
|}

    $msg->send_by_smtp($mail_host);

}

Note that sending mails this way, using the MIME::Lite perl library, you don't need postfix service to run.


Template:TracNotice