diff options
author | Andreas Fischer <bantu@owncloud.com> | 2013-12-14 18:32:48 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@owncloud.com> | 2013-12-14 18:32:48 +0100 |
commit | c205d8d1c957ab5421a5864d183257f596336d2d (patch) | |
tree | a097ff1232f1283074c2cbd589fa1fddac037391 /lib/private/mail.php | |
parent | d73285c1869591da74c148b577d780a73313fe90 (diff) | |
parent | 77b68505c2164330803ce5d5dcbb9fd07438e18d (diff) | |
download | nextcloud-server-c205d8d1c957ab5421a5864d183257f596336d2d.tar.gz nextcloud-server-c205d8d1c957ab5421a5864d183257f596336d2d.zip |
Merge remote-tracking branch 'owncloud/master' into fixing-3417-master
* owncloud/master: (1989 commits)
[tx-robot] updated from transifex
dont try to register background jobs if we haven't upgraded yet
adjust test
coding style
coding style
On webdav sesssions, loginname was compared to username which does not need to match necessarily
rely only on php DateTime to parse the db datetime string
LDAP: fix method behind save button on advancend and expert tabs, fixes at least Home Folder setinng
Fix webroot for update page
Update 3rdparty ref
update 3rdparty
toggle select all checkbox
remove unneeded ; in comment
LDAP: the browser shall not autofill userdn and password, usually login credentials are inserted. fixes #6283
Add test for having utf8 filenames in the cache
fix fallback overwriting result of getHome
[tx-robot] updated from transifex
fix smbclient directory listing parser
cache the home folder of a User
Send "SET NAMES utf8" to MySQL for PHP below 5.3.6
...
Conflicts:
lib/util.php
Diffstat (limited to 'lib/private/mail.php')
-rw-r--r-- | lib/private/mail.php | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/private/mail.php b/lib/private/mail.php new file mode 100644 index 00000000000..b339b33e962 --- /dev/null +++ b/lib/private/mail.php @@ -0,0 +1,133 @@ +<?php +/** + * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * OC_Mail + * + * A class to handle mail sending. + */ + +require_once 'class.phpmailer.php'; + +class OC_Mail { + + /** + * send an email + * + * @param string $toaddress + * @param string $toname + * @param string $subject + * @param string $mailtext + * @param string $fromaddress + * @param string $fromname + * @param bool|int $html + * @param string $altbody + * @param string $ccaddress + * @param string $ccname + * @param string $bcc + * @throws Exception + */ + public static function send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, + $html=0, $altbody='', $ccaddress='', $ccname='', $bcc='') { + + $SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' ); + $SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' ); + $SMTPPORT = OC_Config::getValue( 'mail_smtpport', 25 ); + $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false ); + $SMTPAUTHTYPE = OC_Config::getValue( 'mail_smtpauthtype', 'LOGIN' ); + $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' ); + $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' ); + $SMTPDEBUG = OC_Config::getValue( 'mail_smtpdebug', false ); + $SMTPTIMEOUT = OC_Config::getValue( 'mail_smtptimeout', 10 ); + $SMTPSECURE = OC_Config::getValue( 'mail_smtpsecure', '' ); + + + $mailo = new PHPMailer(true); + if($SMTPMODE=='sendmail') { + $mailo->IsSendmail(); + }elseif($SMTPMODE=='smtp') { + $mailo->IsSMTP(); + }elseif($SMTPMODE=='qmail') { + $mailo->IsQmail(); + }else{ + $mailo->IsMail(); + } + + + $mailo->Host = $SMTPHOST; + $mailo->Port = $SMTPPORT; + $mailo->SMTPAuth = $SMTPAUTH; + $mailo->SMTPDebug = $SMTPDEBUG; + $mailo->SMTPSecure = $SMTPSECURE; + $mailo->AuthType = $SMTPAUTHTYPE; + $mailo->Username = $SMTPUSERNAME; + $mailo->Password = $SMTPPASSWORD; + $mailo->Timeout = $SMTPTIMEOUT; + + $mailo->From = $fromaddress; + $mailo->FromName = $fromname;; + $mailo->Sender = $fromaddress; + $a=explode(' ', $toaddress); + try { + foreach($a as $ad) { + $mailo->AddAddress($ad, $toname); + } + + if($ccaddress<>'') $mailo->AddCC($ccaddress, $ccname); + if($bcc<>'') $mailo->AddBCC($bcc); + + $mailo->AddReplyTo($fromaddress, $fromname); + + $mailo->WordWrap = 50; + if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false); + + $mailo->Subject = $subject; + if($altbody=='') { + $mailo->Body = $mailtext.OC_MAIL::getfooter(); + $mailo->AltBody = ''; + }else{ + $mailo->Body = $mailtext; + $mailo->AltBody = $altbody; + } + $mailo->CharSet = 'UTF-8'; + + $mailo->Send(); + unset($mailo); + OC_Log::write('mail', + 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, + OC_Log::DEBUG); + } catch (Exception $exception) { + OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR); + throw($exception); + } + } + + /** + * return the footer for a mail + * + */ + public static function getfooter() { + + $defaults = new OC_Defaults(); + + $txt="\n--\n"; + $txt.=$defaults->getName() . "\n"; + $txt.=$defaults->getSlogan() . "\n"; + + return($txt); + + } + + /** + * @param string $emailAddress a given email address to be validated + * @return bool + */ + public static function ValidateAddress($emailAddress) { + return PHPMailer::ValidateAddress($emailAddress); + } +} |