Setup CRAM-MD5 authentication for mailing in owncloud Ubuntu

In this tutorial we will learn about how to setup CRAM-MD5 authentication for mailing in Owncloud version 5.0.12-0 in Ubuntu.Today I found that while sharing the link in Owncloud the recipient was not getting email. It was quite obvious I have to set the Mailer. I read the online documentation from owncloud and tried to configure the mail.
I have setup the mail server which only authenticate CRAM-MD5. In Owncloud version 5.0.12 it has 3rd party application called PHPMailer which do not support the CRAM-MD5. The latest PHPMailer version 5.2 has CRAM-MD5 support feature.
In this post we are not using PHPMailer (I believe in next stable release of owncloud the latest PHPMailer will also be updated.)

Here we will use ssmtp . The ssmtp also works with google mail credentials.

Follow the steps to configure the ssmtp in Owncloud for CRAM-MD5 authentication

Step 1: In Ubuntu install the ssmtp


apt-get install ssmtp

Step 2: Configure the ssmtp. You must have the mail server and account details.

Replace:
noreply@example.com with your noreply email id
password-of-noreply means password of email account
mail.smtp.com:25 means mail server FQDN and 25 is port no. of SMTP protocol.

# cp -p /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.orig
# > /etc/ssmtp/ssmtp.conf

Vi /etc/ssmtp/ssmtp.conf

AuthUser=noreply@example.com
AuthPass=password-of-noreply
FromLineOverride=YES
mailhub=mail.smtp.com:25
UseSTARTTLS=YES
AuthMethod=CRAM-MD5

Step 3: Now edit Owncloud config.php . In my server the DircetoryRoot is /var/www/owncloud, replace the DirectoryRoot with the path of installed Owncloud.
Paste the below given contents just above the );

vi /var/www/owncloud/config/config.php

//Mail Server Setting //
 "mail_smtpmode"     => "ssmtp",
 "mail_smtphost"     => "mail.smtp.com",
 "mail_smtpport"     => 25,
 "mail_smtpauth"     => true,
 "mail_smtpauthtype" => "CRAM-MD5",
 "mail_smtpname"     => "noreply@example.com",
 "mail_smtppassword" => "Password",
 "mail_smtpsecure"   => 'tls',

Step 4: Login into owncloud,select some file ,click on sharing. Now share the link and give other email id of yours for testing.
In inbox you will see new email with shared link information. Now open the header of email. (In gmail it is known show original, some mail service provider have ‘Show Details’ tab)
In header you will see Return-Path as sharing-noreply@owncloud.Your-Server.Hostname eg. sharing-noreply@owncloud.sharadchhetri.com.

To change the Return-Path continue with further steps

Note: mail_domain was not working in config.php hence we are following given below steps

Step 5: Edit util.php file. (Take backup of util.php before editing)

cp -p /var/www/owncloud/lib/public/util.php /var/www/owncloud/lib/public/util.php.orig

vi /var/www/owncloud/lib/public/util.php

Note: Do the editing as stated below

In line no. 219 change the $hostname value to your domain(replace example.com)
And in line no. 228 replace example.com to your domain.

218         public static function getDefaultEmailAddress($user_part) {
219                 $host_name = 'example.com';
220                 $defaultEmailAddress = $user_part.'@'.$host_name;
221
222                 if (OC_Mail::ValidateAddress($defaultEmailAddress)) {
223                         return $defaultEmailAddress;
224                 }
225
226                 // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
227                 return $user_part.'@example.com';
228         }

Step 6: Now edit core/ajax/share.php

cp -p /var/www/owncloud/core/ajax/share.php /var/www/owncloud/core/ajax/share.php.orig

vi /var/www/owncloud/core/ajax/share.php

Edit the line. 108 and replace your-email-id with your email id ( you may be seeing here sharing-noreply)

108                         $default_from = OCPUtil::getDefaultEmailAddress('your-email-id');
109                         $from_address = OCPConfig::getUserValue($user, 'settings', 'email', $default_from );

Step 7: Now login into Owncloud. Select any file,click on share,now share the link and give your other email id for testing. Now open the inbox and check the header. The Return-Path should be now noreply@example.com (for eg. you configured noreply@yourdomain.com)

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.