Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit dad1607

Browse files
committed
Merge pull request #1544 from OpenBazaar/test-smtp-settings
Add Test SMTP Server Button
2 parents 9408bc7 + 2861efa commit dad1607

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

js/languages/en-US.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@
187187
"SMTPRecipient": "Recipient Email Address",
188188
"SMTPSenderExample": "[email protected]",
189189
"SMTPSender": "Sender Email Address",
190+
"TestSMTPButton": "Test SMTP Server",
191+
"TestSMTPButtonTooltip": "Test connection to the SMTP server",
190192
"ServerIPPort": "Server IP:Port",
191193
"All": "All",
192194
"Name": "Name",
@@ -531,7 +533,12 @@
531533
"refundAlreadySent": "The refund has already been successfully sent for this order",
532534
"serverTimeout": "No response was received from the server. It may be unreachable or taking a very long time to respond.",
533535
"noData": "No data is available for the options you have selected.",
534-
"loadingViewError": "Loading this page is taking longer than expected."
536+
"loadingViewError": "Loading this page is taking longer than expected.",
537+
"smtpServerError": "SMTP Connection Error",
538+
"smtpServerSuccess": "SMTP Connection Success",
539+
"noSMTPConnection": "The connection to the SMTP server failed.",
540+
"badSMTPAuthentication": "The username/password combination used failed.",
541+
"goodSMTPAuthentication": "You have successfully connected to the SMTP server."
535542
},
536543
"pageConnectingMessages": {
537544
"listingConnect": "Connecting to listing ${listing}",

js/templates/settings.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,12 +1292,14 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
12921292
<div class="flexCol-9 borderRight0 custCol-border">
12931293
<div class="fieldItem flexRow">
12941294
<div class="flexRow">
1295-
<div class="flexCol-4">
1295+
<div class="flexCol-9">
12961296
<input type="radio" class="fieldItem" id="smtpNotificationsYes" name="smtp_notifications" value="true" /><label for="smtpNotificationsYes" class="radioLabel"><%= polyglot.t('Yes') %></label>
12971297
<input type="radio" class="fieldItem" id="smtpNotificationsNo" name="smtp_notifications" value="false" checked/><label for="smtpNotificationsNo" class="radioLabel"><%= polyglot.t('No') %></label>
12981298
</div>
1299-
<div class="flexCol-8">
1300-
<div class="marginLeft10 textSize11px txt-fade"><%= polyglot.t('SMTPNotificationsWarning') %></div>
1299+
<div class="positionTopRight paddingright5">
1300+
<a id="testSMTPButton" class="btn btn-txt js-testSMTP custCol-secondary">
1301+
<%= polyglot.t('TestSMTPButton') %>
1302+
</a>
13011303
</div>
13021304
</div>
13031305
</div>
@@ -1309,7 +1311,7 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
13091311

13101312
<div class="flexCol-3 borderRight custCol-border">
13111313
<div class="fieldItem">
1312-
<label for="resolver">
1314+
<label for="smtpServer">
13131315
<%= polyglot.t('SMTPServer') %>
13141316
</label>
13151317
</div>
@@ -1329,7 +1331,7 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
13291331

13301332
<div class="flexCol-3 borderRight custCol-border">
13311333
<div class="fieldItem">
1332-
<label for="resolver">
1334+
<label for="smtpUsername">
13331335
<%= polyglot.t('SMTPUsername') %>
13341336
</label>
13351337
</div>
@@ -1348,7 +1350,7 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
13481350

13491351
<div class="flexCol-3 borderRight custCol-border">
13501352
<div class="fieldItem">
1351-
<label for="resolver">
1353+
<label for="smtpPassword">
13521354
<%= polyglot.t('SMTPPassword') %>
13531355
</label>
13541356
</div>
@@ -1367,7 +1369,7 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
13671369

13681370
<div class="flexCol-3 borderRight custCol-border">
13691371
<div class="fieldItem">
1370-
<label for="resolver">
1372+
<label for="smtpSender">
13711373
<%= polyglot.t('SMTPSender') %>
13721374
</label>
13731375
</div>
@@ -1387,7 +1389,7 @@ <h3 class="padding15 margin0 fontWeight500"><%= polyglot.t('SMTPNotifications')
13871389

13881390
<div class="flexCol-3 borderRight custCol-border">
13891391
<div class="fieldItem">
1390-
<label for="resolver">
1392+
<label for="smtpRecipient">
13911393
<%= polyglot.t('SMTPRecipient') %>
13921394
</label>
13931395
</div>

js/views/settingsVw.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var __ = require('underscore'),
1616
chosen = require('../utils/chosen.jquery.min.js'),
1717
setTheme = require('../utils/setTheme.js'),
1818
saveToAPI = require('../utils/saveToAPI'),
19+
SMTPConnection = require('smtp-connection'),
1920
MediumEditor = require('medium-editor'),
2021
validateMediumEditor = require('../utils/validateMediumEditor'),
2122
getBTPrice = require('../utils/getBitcoinPrice');
@@ -44,6 +45,7 @@ module.exports = Backbone.View.extend({
4445
'click .js-saveModerator': 'saveModeratorClick',
4546
'click .js-cancelAdvanced': 'cancelView',
4647
'click .js-saveAdvanced': 'saveAdvancedClick',
48+
'click .js-testSMTP': 'testSMTPClick',
4749
'click .js-changeServerSettings': 'launchServerConfig',
4850
'change .js-settingsThemeSelection': 'themeClick',
4951
'click .js-settingsAddressDelete': 'addressDelete',
@@ -659,6 +661,10 @@ module.exports = Backbone.View.extend({
659661
this.saveAdvanced();
660662
},
661663

664+
testSMTPClick: function() {
665+
this.testSMTP();
666+
},
667+
662668
saveGeneral: function() {
663669
var self = this,
664670
form = this.$("#generalForm"),
@@ -970,6 +976,51 @@ module.exports = Backbone.View.extend({
970976
});
971977
},
972978

979+
testSMTP: function(){
980+
var hostport = $('#advancedForm').find('input[name="smtp_server"]').val();
981+
hostport = hostport.split(':');
982+
983+
$('#testSMTPButton').addClass('loading');
984+
985+
var connection = new SMTPConnection({
986+
host: hostport[0],
987+
port: hostport[1]
988+
});
989+
990+
connection.on('error', function(){
991+
$('#testSMTPButton').removeClass('loading');
992+
messageModal.show(
993+
window.polyglot.t('errorMessages.smtpServerError'),
994+
window.polyglot.t('errorMessages.noSMTPConnection')
995+
);
996+
}
997+
);
998+
999+
connection.connect(function() {
1000+
1001+
var username = $('#advancedForm').find('input[name="smtp_username"]').val();
1002+
var password = $('#advancedForm').find('input[name="smtp_password"]').val();
1003+
1004+
connection.login({
1005+
user: username,
1006+
pass: password
1007+
}, function(err) {
1008+
if(err) {
1009+
messageModal.show(
1010+
window.polyglot.t('errorMessages.smtpServerError'),
1011+
window.polyglot.t('errorMessages.badSMTPAuthentication')
1012+
);
1013+
} else {
1014+
messageModal.show(
1015+
window.polyglot.t('errorMessages.smtpServerSuccess'),
1016+
window.polyglot.t('errorMessages.goodSMTPAuthentication')
1017+
);
1018+
}
1019+
$('#testSMTPButton').removeClass('loading');
1020+
})
1021+
})
1022+
},
1023+
9731024
saveAdvanced: function(){
9741025
var self = this,
9751026
form = this.$("#advancedForm"),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"request": ">=2.67.0",
3838
"safestart": "0.8.0",
3939
"sanitize-html": "^1.11.2",
40+
"smtp-connection": "^2.5.0",
4041
"sortablejs": "^1.4.2",
4142
"taggle": "1.6.1",
4243
"underscore": "1.8.3",

0 commit comments

Comments
 (0)