Showing posts with label e-mail. Show all posts
Showing posts with label e-mail. Show all posts

Thursday, May 15, 2014

ssmtp to email cron output

Cron output in Ubuntu gets discarded. The default install of Ubuntu does not install a Mail Transport Agent (MTA), so cron cannot mail you the output.

You can install an MTA -several are easily available in the Ubuntu repositories- but configuration is not trivial. MTAs date from before the IMAP- and SMTP-based e-mail systems we use today, which makes them highly flexible and configurable...but not necessarily the easiest solution.

ssmtp is a limited-purpose MTA intended to replace the 'mail' command and send all output to an SMTP mailserver. ssmtp is provided by the 'ssmtp' package.

Install


sudo apt-get install ssmtp

Configuration file #1: /etc/ssmtp/ssmpt.conf

This tells ssmtp how to send email to my account.
It's not the best idea to store your e-mail password in world-readable plain text. See how to protect the password properly.

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=me@example.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=my_mail_server.net:465
AuthUser=me@example.com
AuthPass=my_email_password
UseTLS=Yes

# Where will the mail seem to come from?
rewriteDomain=example.com

# The full hostname
hostname=hey_its_my_computer

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES


Configuration File #2: /etc/ssmtp/

This directs root mail to my account.

# sSMTP aliases
#
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root:me@example.com:my_mail_server.net:465



And now cron output lands in my normal inbox.

Monday, June 3, 2013

Pre-filling an Outlook Express mail in Windows XP

I want a Python3 script to open a pre-filled Outlook Express (OE) new-mail window. A human should read, edit, and approve the e-mail before sending. If I wanted a completely automatic e-mail, I would use Python's smtp module.

The problem is that OE has no COM server, and the Simple-MAPI support is in C++.




Command Line

There is an easy way from the Windows command line:

C:>"C:\Program Files\Outlook Express\msimn" /mailurl:mailto:"name%40example.com?cc=cc1%40example.com&bcc=bcc1@example.com&subject=The%20Subject%20Line&body=The%20first%20paragraph.%0A%0AThe%20second%20paragraph.%0A%0AThanks%2C%0AName

This launches OE with a single argument. That argument is a mailto: URL. The URL includes to:, cc:, bcc:, subject:, and the body.
  • "C:\Program Files\Outlook Express\msimn" launches OE
  • /mailurl:mailto:" defines the mailto: URL. The quote(") is required on the command line, though not in the python version.
  • name%40example.com? is the To: line. The To: line ends with the question-mark (?)
  • cc=cc1%40example.com& the rest of the fields are defined (cc=) and separated with the ampersand (&).
  • Don't use spaces or commas or returns - just text.
    space%20
    ,%2C
    return%0A
    @%40
  • I have not figured out a way to include more than one e-mail address on each line.
  • Files cannot be attached using this method.




Python

Since OE does not have any COM or other programmatic way to do it, we will fall back on subprocess, and have Python simply create a mailto: URL and use the command line.

This simple Python3 script creates a pre-filled Outlook Express window using subprocess:


import subprocess

# The header and body
to      = "name1%40example.com"
cc      = "cc1%40example.com"     # or leave blank: cc = ""
bcc     = "bcc1%40example.com"    # or leave blank: bcc = ""
subject = "The%20Subject"
body    = "The%20first%20paragraph.%0A%0AThe%20second%20paragraph.%0A%0AThanks%2C%0AName"

oe = "C:\Program Files\Outlook Express\msimn"
mailto_url = ('/mailurl:mailto:' + to      + '?' +   # No lone quote (") after colon (:)
              'cc='              + cc      + '&' +
              'bcc='             + bcc     + '&' +
              'subject='         + subject + '&' +
              'body='            + body )            # No ending ampersand (&) 

subprocess.call([oe, mailto_url])

Saturday, June 27, 2009

Reinstalling Xubuntu 9.04

About a month ago, audio suddenly stopped working. Rather than troubleshoot, I decided to reinstall...it might be faster. Unlike last time, this time was a complete reinstall to get rid of certain dependency problems that had also cropped up.

  • Wireless networking worked immediately.
  • Oops. I didn't backup any of my *hidden* files - suddenly all of my e-mail and web caches are...gone. Lesson - keep older backups. Lesson - copy hidden files, too.
  • I tried using Jablicator to save my package list, but hit a failure - it couldn't resolve libdvdcss2 because it didn't come from the Ubuntu repositories.
  • Audio works in the Listen player - except wma files. Totem plays the wma, so it's not a codec or dependency issue. Streaming .pls works.
  • Video works. Added Flash, and YouTube and Hulu work. DVD read works after just a bit of tweaking

Monday, April 27, 2009

The Evolution plugin for Mail Notification doesn't work/exist (LP#355209)

In mail-notification 5.4 in Ubuntu Jaunty (9.04), the following files are installed to /usr/lib/evolution/2.24/plugins/ instead of /usr/lib/evolution/2.26/plugins/:
liborg-jylefort-mail-notification.so
org-jylefort-mail-notification.eplug


    A simple workaround:
  1. Copy or link the files to the correct directory:
    sudo ln -s /usr/lib/evolution/2.24/plugins/org-jylefort-mail-notification.eplug /usr/lib/evolution/2.26/plugins/
    sudo ln -s /usr/lib/evolution/2.24/plugins/liborg-jylefort-mail-notification.so /usr/lib/evolution/2.26/plugins/
  2. Restart evolution and go to Edit -> Plugins -> Jean-Yves Lefort's Mail Notification. Check the box.
  3. Right-click on the Mail-Notification icon -> Properties. Add your evolution e-mailbox.

Thursday, July 24, 2008

Creating an Evolution e-mail from the command line and python

Evolution is intended as a GUI e-mail client, so the scripting options are limited. Also, it looks like you cannot autosend e-mail from a script, there's so script command equivalent to the 'send' button.


But that's a good thing; I can autosend from nail when I want to. So a script will compose the e-mail, which will sit on my desktop until I review it and click to send it. Nice.


shell command source

This command creates a window with To:, From:, Subject:, and Body filled in. 'From:' is already known by Evolution, the rest is parsed from the following command:

evolution mailto:person@example.com?subject=Test\&body=Some%20crazy%20story%20stuff%0D%0Acolumn1%09%09column2%09%09column3%0D%0A%0D%0ASincerely,%0D%0A%0D%0AMe


Another (easier) way:
evolution mailto:person@example.com?cc="second_person@example.com"\&subject="This Is The Subject"\&body="This is the body of the message"\&attach=Desktop/test_file.xml
  • evolution mailto:person@example.com - Launches Evolution's e-mail composer and To: line
  • ?cc="Person@example.com" - CC: Line
  • \&subject="Subject" or ?subject="Subject" - Subject line
  • \&body="Body" - Body of the e-mail is everything after this line
  • \&attach=/path/file - Files to attach
  • %20 - Space
  • %0D%0A - CR/LF (new line)
  • %09 - Tab

python command

Python 2.x has it's own smtp module for creating e-mail, it's far more useful in most circumstances. But in this case, we want the composed evolution window.

import os
body_string = 'This is the body of the e-mail message'
body_string = body_string.replace(' ','%20')
os.popen('evolution mailto:person@example.com?subject=Test\&body=' + body_string)
  • import os - Use python's os module
  • body_string = 'This is the body of the e-mail message' - The body in normal text
  • body_string = body_string.replace(' ','%20') - Encode the spaces (evolution will decode them). Tabs, newlines, and other reserved strings need to be encoded.
  • os.popen('evolution mailto:person@example.com?subject=Test\&body=' + body_string) - The 'os.popen(cmd)' executes shell cmd. Note that cmd is just a python string, and you can use all the string tools on it, like adding body_string.
>>> import os
>>> to = 'person@example.com'
>>> cc = '"second_person@example.com"'
>>> subject = '"This is the subject"'
>>> body = '"This is the body"'
>>> attachment = 'Desktop/rss_test.xml'
>>> os.popen('evolution mailto:'+to+'?cc='+cc+'\&subject='+subject+'\&body='+body+'\&attachment='+attachment)