9. February 2017

Courier Mail Server stops delivering emails after upgrade to 0.76

It might seem like a minor upgrade to go from version 0.75 to 0.76. In the case of Courier Mail Server, it’s a huge change in the orchestration of services.

Courier Mail Server has a very good modular architecture which allows independent control of each aspect of mail delivery. You can separately restart or change each service like MTA, POP or IMAP. Even encrypted variants of servers are available as separate services. The version 0.76 is pushing it even further in the fashion of micro services.

There is new service ‘courier’ which is responsible for scheduling mail delivery after mail was accepted via SMTP or SMTP-SSL. If you’re not aware of this new service you might wonder why is Courier not logging any activity after accepting email. Just make sure that service is running. You can start it by:

service courier start

After the start of the service, you may see that emails are being processed, but they’re not delivered to local mail users. In the log, you can find many error messages like:

/usr/bin/maildrop: Unable to change to home directory.

The other major change is the switch from courier-maildrop to common maildrop. That might seem like a minor change, but it could render your server completely useless. Emails won’t be simply delivered to user’s mailbox:

/usr/bin/maildrop: Unable to change to home directory.

The problem is that maildrop is accepting different parameters than courier-maildrop. Package maintainers recommends to change line with maildrop in /etc/courier/esmtpd from:

DEFAULTDELIVERY='|/usr/bin/maildrop'

to:

DEFAULTDELIVERY='|/usr/bin/maildrop -w 90 -V 1 -d ""'

If you do not have time to play with maildrop, you can change to default configuration:

DEFAULTDELIVERY=./Maildir

Here is the explanation of changes from package maintainers (click image for detail):

Restart services and delivery should start. It might happen that services do not shut down, because upgrade changed user from ‘daemon‘ to ‘courier‘. Then the solution is to terminate services by:

pkill -9 -f courier

Then you can start services and everything should work ok.

28. January 2010

Zarafa.com – opravy pre VMime

Narazil som na problém, že jedna zo starších verzií VMime nepodporuje tzv. foldovanie hlavičiek v maili. RFC2822 folding definuje tak, že ak je riadok dlhší ako 70 znakov, je ho možné rozdeliť na ďalšie riadky. Príklad:

From:
 Johny Geokeska <keska@sinusgear.com>

Výsledok parsovania takéhoto mailu bol, že pri pokuse o získanie “From” som dostal prázdny reťazec. Oprava je celkom jednoduchá a spočíva len v správnom stanovení podmienok.

Veľmi dobrý zdroj patchov a opráv pre libvmime nájdete na stránkach Zarafa.com. Patch na problém s foldingom sa volá: vmime-header-value-on-next-line.diff

28. October 2009

Odosielanie mailu s diakritikou z Pythonu

Jaj. To som zase mal veľkú radosť, keď som zistil, že TurboMail má problémy s odosielaním mailov s diakritikou. Ja chápem, že ľudí v anglofónnych krajinách príliš netrápia nejaké tie srandovné veci nad písmenkami. Bez diakritiky je aplikácia pre Európu bezcenná.

Tak, dosť lamentu. Ako poslať z Pythonu mail v UTF-8?

Tu je kód, ktorý som prevzal od Mariusa Gedminasa a rozšíril som ho o pár riadkov, aby bol priamo spustiteľný.

# -*- coding: utf-8 -*-
from smtplib import SMTP
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import parseaddr, formataddr

def send_email(sender, recipient, subject, body):
    """Send an email. All arguments should be Unicode strings (plain ASCII works as well). Only the real name part of sender and recipient addresses may contain non-ASCII characters. The email will be properly MIME encoded and delivered though SMTP to localhost port 25. This is easy to change if you want something different. The charset of the email will be the first one out of US-ASCII, ISO-8859-1 and UTF-8 that can represent all the characters occurring in the email. """

    # Header class is smart enough to try US-ASCII, then the charset we
    # provide, then fall back to UTF-8.
    header_charset = 'ISO-8859-1'

    # We must choose the body charset manually
    for body_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
        try:
            body.encode(body_charset)
        except UnicodeError:
            pass
        else:
            break

    # Split real name (which is optional) and email address parts
    sender_name, sender_addr = parseaddr(sender)
    recipient_name, recipient_addr = parseaddr(recipient)

    # We must always pass Unicode strings to Header, otherwise it will
    # use RFC 2047 encoding even on plain ASCII strings.
    sender_name = str(Header(unicode(sender_name), header_charset))
    recipient_name = str(Header(unicode(recipient_name), header_charset))

    # Make sure email addresses do not contain non-ASCII characters
    sender_addr = sender_addr.encode('ascii')
    recipient_addr = recipient_addr.encode('ascii')

    # Create the message ('plain' stands for Content-Type: text/plain)
    msg = MIMEText(body.encode(body_charset), 'plain', body_charset)
    msg['From'] = formataddr((sender_name, sender_addr))
    msg['To'] = formataddr((recipient_name, recipient_addr))
    msg['Subject'] = Header(unicode(subject), header_charset)

    # Send the message via SMTP to localhost:25
    smtp = SMTP("localhost")
    smtp.sendmail(sender, recipient, msg.as_string())
    smtp.quit()

send_email('odosielatel@sinusgear.com',
 'prijemca@sinusgear.com',
 u'Guľôčka v jamôčke',
 u"""Lečo, haruľa, šašlík.
A ako dopadne odosielanie ďalšieho riadku? Bude na novom riadku.
A čo tak odoslať trošku dlhší reťazec znakov, než obyčajných 80, aby sme videli, ako si s tým mailer programy poradia. """)

Všetko. Stačí uložiť do send.py a zavolať: python send.py

Tisíce ďakovných listov od spokojných Pythonierov a neskonalá vďaka Mariusovi.

10. January 2009

Odosielanie mailu s diakritikou z PHP

Narazil som na drobný problém pri odosielaní mailov z PHP. A síce, že maily s diakritikou chodili označené ako corrupted a nie veľmi čitateľné. Povedal, som si, že na odosielanie skúsim použiť triedy z Pear. Tu som narazil na prvý problém, že include Pear súborov, bol zablokovaný safe módom. Riešenie bolo jednoduché, stačilo pridať správne premenné do konfigurácie Apacha. Finta bola v tom, že adresár, kde sa nachádajú Pear kódy musí byť zároveň v open_basedir aj v safe_mode_include.

php_admin_value open_basedir /home/georgik/www:/usr/local/share/pear
php_admin_value safe_mode_include_dir /usr/local/share/pear

Pear síce nevyrišiel problém s odosielaním UTF-8 mailov, ale minimálne použitie tried v PHP prospieva k udržateľnosti kódu. To podstatné boli hlavičky, ktoré bolo nutné do e-mailu pridať.

Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

No a celý kód vyzerá nasledovne.

/**
 * Send UTF-8 formated e-mail using PHP Pear Mail classes.
 * 
 * @param recipient E-mail address where you want to deliver e-mail.
 * @param subject Subject of e-mail.
 * @param text UTF-8 content of e-mail.
 */
function sendEmail($recipient, $subject, $text)
{
    include('Mail.php');
    include('Mail/mime.php');

    $mail = Mail::factory("mail");

    $headers = array(
        'From' => "priklad-z-blogu@asinus.cz",
        'Subject' => $subject,
        'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
        'Content-Transfer-Encoding' => '8bit',
    );

    $mime = new Mail_mime("\n");

    $mime->setTXTBody($text);

    $body = $mime->get( array ('head_charset' => 'UTF-8',
        'head_encoding' => 'quoted-printable',
        'text_charset' => 'UTF-8',
        'html_charset' => 'UTF-8'));

    $mail->send($recipient, $headers, $body);
}

sendEmail('objednavky@asinus.org', 'Objednavka',
          'Dobrý deň. Rád by som si u Vás objednal hosting a žinčicu. S pozdravom Janko Paľko z Malužinej');
  • Where’s the fish?

  • Translations

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics