Skip to content

Commit 573e7dc

Browse files
authored
add smtp2go (#2042)
1 parent 6603848 commit 573e7dc

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

addons/smtp-mail.sh

+63-10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ choice=$(whiptail --title "$TITLE" --nocancel --menu \
5050
"Please choose the mail provider that you want to use.
5151
$MENU_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
5252
"mail.de" "(German mail provider)" \
53+
"SMTP2GO" "(https://www.smtp2go.com)" \
5354
"Manual" "(Complete manual setup)" 3>&1 1>&2 2>&3)
5455

5556
case "$choice" in
@@ -59,6 +60,13 @@ case "$choice" in
5960
PROTOCOL="SSL"
6061
SMTP_PORT="465"
6162
;;
63+
"SMTP2GO")
64+
NEEDS_CREDENTIALS=1
65+
SMTP2GO=1
66+
MAIL_SERVER="mail-eu.smtp2go.com"
67+
PROTOCOL="SSL"
68+
SMTP_PORT="465"
69+
;;
6270
# Manual setup will be handled a few lines below
6371
"")
6472
msg_box "You haven't selected any option. Exiting!"
@@ -131,7 +139,7 @@ fi
131139
# Enter your SMTP username
132140
if [ -n "$NEEDS_CREDENTIALS" ] || yesno_box_yes "Does $MAIL_SERVER require any credentials, like username and password?"
133141
then
134-
MAIL_USERNAME=$(input_box_flow "Please enter the SMTP username to your email provider.\nE.g. [email protected]")
142+
MAIL_USERNAME=$(input_box_flow "Please enter the SMTP username to your email provider.\nE.g. [email protected], or just the actual 'username'.")
135143

136144
# Enter your mail user password
137145
MAIL_PASSWORD=$(input_box_flow "Please enter the SMTP password to your email provider.")
@@ -198,6 +206,34 @@ account default : $MAIL_USERNAME
198206
199207
### DO NOT REMOVE THIS LINE (it's used in one of the functions in on the Nextcloud Server)
200208
# recipient=$RECIPIENT
209+
MSMTP_CONF
210+
elif [ -n "$SMTP2GO" ]
211+
then
212+
# With AUTH (Username and Password)
213+
cat << MSMTP_CONF > /etc/msmtprc
214+
# Set default values for all following accounts.
215+
defaults
216+
auth on
217+
aliases /etc/aliases
218+
$MSMTP_ENCRYPTION1
219+
$MSMTP_ENCRYPTION2
220+
221+
tls_trust_file /etc/ssl/certs/ca-certificates.crt
222+
logfile /var/log/msmtp
223+
224+
# Account to send emails
225+
account $MAIL_USERNAME
226+
host $MAIL_SERVER
227+
port $SMTP_PORT
228+
229+
user $MAIL_USERNAME
230+
password $MAIL_PASSWORD
231+
232+
account default : $MAIL_USERNAME
233+
234+
### DO NOT REMOVE THIS LINE (it's used in one of the functions in on the Nextcloud Server)
235+
# recipient=$RECIPIENT
236+
201237
MSMTP_CONF
202238
else
203239
# With AUTH (Username and Password)
@@ -265,18 +301,25 @@ echo 'set sendmail="/usr/bin/msmtp -t"' > /etc/mail.rc
265301
# Test mail
266302
if ! echo -e "$TEST_MAIL" | mail -s "Test email from your NcVM" "$RECIPIENT" >> /var/log/msmtp 2>&1
267303
then
268-
# Test another version
269-
echo 'set sendmail="/usr/bin/msmtp"' > /etc/mail.rc
270-
304+
# Set from email address
305+
sed -i "s|from .*|from [email protected]|g" /etc/msmtprc
306+
271307
# Second try
272308
if ! echo -e "$TEST_MAIL" | mail -s "Test email from your NcVM" "$RECIPIENT" >> /var/log/msmtp 2>&1
273309
then
274-
# Fail message
275-
msg_box "It seems like something has failed.
310+
# Test another version
311+
echo 'set sendmail="/usr/bin/msmtp"' > /etc/mail.rc
312+
313+
# Third try
314+
if ! echo -e "$TEST_MAIL" | mail -s "Test email from your NcVM" "$RECIPIENT" >> /var/log/msmtp 2>&1
315+
then
316+
# Fail message
317+
msg_box "It seems like something has failed.
276318
You can look at /var/log/msmtp for further logs.
277319
Please run this script once more if you want to make another try or \
278320
if you want to deinstall all newly installed packages."
279-
exit 1
321+
exit 1
322+
fi
280323
fi
281324
fi
282325

@@ -285,7 +328,7 @@ msg_box "Congratulations, the test email was successfully sent!
285328
Please check the inbox for $RECIPIENT. The test email should arrive soon."
286329

287330
# Only offer to use the same settings in Nextcloud if a password was chosen
288-
if [ "$MAIL_USERNAME" = "[email protected]" ]
331+
if [ "$MAIL_USERNAME" = "[email protected]" ] && [ -z "$SMTP2GO" ]
289332
then
290333
exit
291334
fi
@@ -316,8 +359,18 @@ fi
316359
# Authentification
317360
nextcloud_occ config:system:set mail_smtpauthtype --value="LOGIN"
318361
nextcloud_occ config:system:set mail_smtpauth --type=integer --value=1
319-
nextcloud_occ config:system:set mail_from_address --value="${MAIL_USERNAME%%@*}"
320-
nextcloud_occ config:system:set mail_domain --value="${MAIL_USERNAME##*@}"
362+
if [ -n "$SMTP2GO" ]
363+
then
364+
nextcloud_occ config:system:set mail_from_address --value="no-reply"
365+
else
366+
nextcloud_occ config:system:set mail_from_address --value="${MAIL_USERNAME%%@*}"
367+
fi
368+
if [ -n "$SMTP2GO" ]
369+
then
370+
nextcloud_occ config:system:set mail_domain --value="nextcloudvm.com"
371+
else
372+
nextcloud_occ config:system:set mail_domain --value="${MAIL_USERNAME##*@}"
373+
fi
321374
nextcloud_occ config:system:set mail_smtphost --value="$MAIL_SERVER"
322375
nextcloud_occ config:system:set mail_smtpport --value="$SMTP_PORT"
323376
nextcloud_occ config:system:set mail_smtpname --value="$MAIL_USERNAME"

0 commit comments

Comments
 (0)