├── LICENSE ├── README.markdown ├── composer.json ├── crowdin.yaml ├── identity_smtp.js ├── identity_smtp.php └── localization ├── ca_ES.inc ├── de_DE.inc ├── en_US.inc ├── es_ES.inc ├── fr_FR.inc ├── ja_JP.inc └── pl_PL.inc /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # identity_smtp Roundcube Plugin 2 | 3 | This Roundcube plugin allows you to setup identities with different SMTP servers 4 | from the RC installation's default. 5 | 6 | ## Installation 7 | 8 | This plugin is available from [Packagist](https://packagist.org/packages/elm/identity_smtp). 9 | 10 | ### Manual Installation 11 | 12 | $ cd /path/to/roundcube/plugins 13 | $ git clone https://github.com/deflomu/Roundcube-SMTP-per-Identity-Plugin.git identity_smtp 14 | 15 | To use a specific version: 16 | 17 | $ git checkout 1.6.0 18 | 19 | Replace `1.6.0` with any version found [here](https://github.com/deflomu/Roundcube-SMTP-per-Identity-Plugin/tags) 20 | 21 | The plugins folder must be named identity_smtp. 22 | 23 | Add `identity_smtp` to `$rcmail_config['plugins']` in `config/main.inc.php`. 24 | 25 | A default SMTP server has to be set in `config/main.inc.php`, otherwise 26 | Roundcube will not call any SMTP function and the plugin will not work. 27 | 28 | ## Versions 29 | 30 | Each version's Major + Minor will match the latest version of Roundcube that it's compatible with. 31 | If you cannot find a version for your install, use the closest-matching newer version. 32 | 33 | ## Usage 34 | 35 | In the `Identities` settings you can specify an alternative SMTP server for every 36 | identity to send mail with. When composing an email, just choose the identity you 37 | want to use to send mail. 38 | 39 | ## Examples 40 | 41 | ### Gmail 42 | 43 | #### Roundcube 1.6+ 44 | 45 | * Server Host: `tls://smtp.gmail.com:587` 46 | * Username: `example@gmail.com` 47 | * Password: `HighlySecurePassw0rd` 48 | 49 | #### Roundcube 1.5 & below 50 | 51 | * Server IP/Hostname: `tls://smtp.gmail.com` 52 | * Server Port: `587` 53 | * Username: `example@gmail.com` 54 | * Password: `HighlySecurePassw0rd` 55 | 56 | Note: As of 30/MAY/2022 Google blocks sending email using your account's password. 57 | To get a working password for sending email, please use an [App Specific Password](https://support.google.com/accounts/answer/185833?hl=en). 58 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elm/identity_smtp", 3 | "description": "Individual SMTP settings for every identity", 4 | "keywords": ["mail","smtp","settings","identity"], 5 | "homepage": "https://github.com/deflomu/Roundcube-SMTP-per-Identity-Plugin", 6 | "type": "roundcube-plugin", 7 | "license": "MIT", 8 | "repositories": [ 9 | { 10 | "type": "composer", 11 | "url": "http://plugins.roundcube.net" 12 | } 13 | ], 14 | "require": { 15 | "roundcube/plugin-installer": ">=0.1.3" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /crowdin.yaml: -------------------------------------------------------------------------------- 1 | files: 2 | - source: /localization/en_US.inc 3 | translation: /localization/%locale_with_underscore%.inc 4 | -------------------------------------------------------------------------------- /identity_smtp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Per identity smtp settings 4 | * 5 | * Description 6 | * 7 | * @version 0.1 8 | * @author elm@skweez.net, ritze@skweez.net, mks@skweez.net 9 | * @url skweez.net 10 | * 11 | * MIT License 12 | * 13 | **/ 14 | 15 | function identity_smtp_toggle_standard_server() { 16 | var checkbox = $('input[name=_smtp_standard]'); 17 | if (checkbox.is(':checked')) { 18 | $('.identity_smtp_form').prop('disabled', true); 19 | } else { 20 | $('.identity_smtp_form').prop('disabled', false); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /identity_smtp.php: -------------------------------------------------------------------------------- 1 | include_script('identity_smtp.js'); 24 | $this->add_texts('localization/', true); 25 | 26 | $this->add_hook('message_before_send', array( 27 | $this, 28 | 'messageBeforeSend' 29 | )); 30 | $this->add_hook('smtp_connect', array( 31 | $this, 32 | 'smtpWillConnect' 33 | )); 34 | $this->add_hook('identity_form', array( 35 | $this, 36 | 'identityFormWillBeDisplayed' 37 | )); 38 | $this->add_hook('identity_create', array( 39 | $this, 40 | 'identityWasCreated' 41 | )); 42 | $this->add_hook('identity_update', array( 43 | $this, 44 | 'identityWasUpdated' 45 | )); 46 | $this->add_hook('identity_delete', array( 47 | $this, 48 | 'identityWasDeleted' 49 | )); 50 | } 51 | 52 | function smtpLog($message) 53 | { 54 | rcube::write_log("identity_smtp_plugin", $message); 55 | } 56 | 57 | function saveSmtpSettings($args) 58 | { 59 | $identities = rcmail::get_instance()->config->get('identity_smtp'); 60 | $id = intval($args['id']); 61 | 62 | if (!isset($identities)) { 63 | $identities = array(); 64 | } 65 | 66 | $smtp_standard = rcube_utils::get_input_value('_smtp_standard', rcube_utils::INPUT_POST); 67 | 68 | $password = rcube_utils::get_input_value('_smtp_pass', rcube_utils::INPUT_POST, true); 69 | $password2 = rcube_utils::get_input_value('_smtp_pass2', rcube_utils::INPUT_POST, true); 70 | 71 | if ($password != $password2) { 72 | $args['abort'] = true; 73 | $args['result'] = false; 74 | $args['message'] = $this->gettext('smtp_passwords_mismatch'); 75 | return $args; 76 | } 77 | 78 | if ($password != $identities[$id]['smtp_pass']) { 79 | $password = rcmail::get_instance()->encrypt($password); 80 | } 81 | 82 | $smtpSettingsRecord = array( 83 | 'smtp_standard' => isset($smtp_standard), 84 | 'smtp_host' => rcube_utils::get_input_value('_smtp_host', rcube_utils::INPUT_POST), 85 | 'smtp_user' => rcube_utils::get_input_value('_smtp_user', rcube_utils::INPUT_POST), 86 | 'smtp_pass' => $password 87 | ); 88 | 89 | unset($identities[$id]); 90 | $identities += array( 91 | $id => $smtpSettingsRecord 92 | ); 93 | rcmail::get_instance()->user->save_prefs(array( 94 | 'identity_smtp' => $identities 95 | )); 96 | 97 | return $args; 98 | } 99 | 100 | function loadSmtpSettings($args) 101 | { 102 | $smtpSettings = rcmail::get_instance()->config->get('identity_smtp'); 103 | $id = intval($args['identity_id']); 104 | $smtpSettingsRecord = array( 105 | 'smtp_standard' => $smtpSettings[$id]['smtp_standard'], 106 | 'smtp_host' => $smtpSettings[$id]['smtp_host'], 107 | 'smtp_user' => $smtpSettings[$id]['smtp_user'], 108 | 'smtp_pass' => $smtpSettings[$id]['smtp_pass'], 109 | 'smtp_pass2' => $smtpSettings[$id]['smtp_pass'] 110 | ); 111 | 112 | if (is_null($smtpSettingsRecord['smtp_standard'])) { 113 | $smtpSettingsRecord['smtp_standard'] = true; 114 | } 115 | 116 | return $smtpSettingsRecord; 117 | } 118 | 119 | function identityFormWillBeDisplayed($args) 120 | { 121 | $form = $args['form']; 122 | $record = isset($args['record']) ? $args['record'] : []; 123 | 124 | 125 | // Load the stored smtp settings 126 | $smtpSettingsRecord = $this->loadSmtpSettings($record); 127 | 128 | if (!isset($record['identity_id'])) { 129 | // FIX ME 130 | $smtpSettingsForm = array( 131 | 'smtpSettings' => array( 132 | 'name' => $this->gettext('smtp_settings_header'), 133 | 'content' => array( 134 | 'text' => array( 135 | 'label' => $this->gettext('smtp_settings_not_available'), 136 | 'value' => ' ' 137 | ) 138 | ) 139 | ) 140 | ); 141 | } else { 142 | $smtpSettingsForm = array( 143 | 'smtpSettings' => array( 144 | 'name' => $this->gettext('smtp_settings_header'), 145 | 'content' => array( 146 | 'smtp_standard' => array( 147 | 'type' => 'checkbox', 148 | 'label' => $this->gettext('use_default_smtp_server'), 149 | 'onclick' => 'identity_smtp_toggle_standard_server()' 150 | ), 151 | 'smtp_host' => array( 152 | 'type' => 'text', 153 | 'label' => $this->gettext('smtp_host'), 154 | 'class' => 'identity_smtp_form', 155 | 'size' => 40 156 | ), 157 | 'smtp_user' => array( 158 | 'type' => 'text', 159 | 'label' => $this->gettext('smtp_user'), 160 | 'class' => 'identity_smtp_form', 161 | 'size' => 40 162 | ), 163 | 'smtp_pass' => array( 164 | 'type' => 'password', 165 | 'label' => $this->gettext('smtp_pass'), 166 | 'class' => 'identity_smtp_form', 167 | 'size' => 40 168 | ), 169 | 'smtp_pass2' => array( 170 | 'type' => 'password', 171 | 'label' => $this->gettext('smtp_pass2'), 172 | 'class' => 'identity_smtp_form', 173 | 'placeholder' => 'test', 174 | 'size' => 40 175 | ) 176 | ) 177 | ) 178 | ); 179 | if ($smtpSettingsRecord['smtp_standard'] || is_null($smtpSettingsRecord['smtp_standard'])) { 180 | foreach ($smtpSettingsForm['smtpSettings']['content'] as &$input) { 181 | if ($input['type'] != 'checkbox') { 182 | $input['disabled'] = 'disabled'; 183 | } 184 | } 185 | } 186 | } 187 | $form = $form + $smtpSettingsForm; 188 | $record = $record + $smtpSettingsRecord; 189 | 190 | $OUTPUT = array( 191 | 'form' => $form, 192 | 'record' => $record 193 | ); 194 | return $OUTPUT; 195 | } 196 | 197 | // This function is called when a new identity is created. We want to use the default smtp server here 198 | function identityWasCreated($args) 199 | { 200 | $args = $this->saveSmtpSettings($args); 201 | return $args; 202 | } 203 | 204 | // This function is called when the users saves a changed identity. It is responsible for saving the smtp settings 205 | function identityWasUpdated($args) 206 | { 207 | $args = $this->saveSmtpSettings($args); 208 | return $args; 209 | } 210 | 211 | function identityWasDeleted($args) 212 | { 213 | $smtpSettings = rcmail::get_instance()->config->get('identity_smtp'); 214 | $id = $args['id']; 215 | unset($smtpSettings[$id]); 216 | rcmail::get_instance()->user->save_prefs(array( 217 | 'identity_smtp' => $smtpSettings 218 | )); 219 | 220 | // Return false to not abort the deletion of the identity 221 | return false; 222 | } 223 | 224 | function messageBeforeSend($args) 225 | { 226 | $identities = rcmail::get_instance()->user->list_identities(); 227 | foreach ($identities as $idx => $ident) { 228 | if ($identities[$idx]['email'] == $args['from']) { 229 | $this->from_identity = $identities[$idx]['identity_id']; 230 | } 231 | } 232 | return $args; 233 | } 234 | 235 | // This function is called when an email is sent and it should pull the correct smtp settings for the used identity and insert them 236 | function smtpWillConnect($args) 237 | { 238 | $smtpSettings = $this->loadSmtpSettings(array( 239 | 'identity_id' => $this->from_identity 240 | )); 241 | if (!$smtpSettings['smtp_standard'] && !is_null($smtpSettings['smtp_standard'])) { 242 | $args['smtp_host'] = $smtpSettings['smtp_host']; 243 | $args['smtp_user'] = $smtpSettings['smtp_user']; 244 | $args['smtp_pass'] = rcmail::get_instance()->decrypt($smtpSettings['smtp_pass']); 245 | } 246 | return $args; 247 | } 248 | } 249 | ?> 250 | -------------------------------------------------------------------------------- /localization/ca_ES.inc: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /localization/de_DE.inc: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /localization/en_US.inc: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /localization/es_ES.inc: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /localization/fr_FR.inc: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /localization/ja_JP.inc: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /localization/pl_PL.inc: -------------------------------------------------------------------------------- 1 | 15 | --------------------------------------------------------------------------------