forked from opf/openproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-test-email
More file actions
executable file
·45 lines (39 loc) · 1.37 KB
/
Copy pathsend-test-email
File metadata and controls
executable file
·45 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
require 'net/smtp'
require 'time'
require 'securerandom'
require 'tempfile'
admin_email = ENV.fetch('ADMIN_EMAIL') { fail "no ADMIN_EMAIL set" }
smtp_domain = ENV.fetch('SMTP_DOMAIN') { "example.net" }
from = "no-reply@#{smtp_domain}"
delivery_method = ENV.fetch('EMAIL_DELIVERY_METHOD') { "sendmail" }
msgstr = <<END_OF_MESSAGE
From: OpenProject <#{from}>
To: #{admin_email}
Subject: Test message
Date: #{Time.now.httpdate}
Message-Id: <#{SecureRandom.hex}@#{smtp_domain}>
This is a test message to verify your OpenProject settings.
If you see this, this means OpenProject email settings are working properly.
END_OF_MESSAGE
if delivery_method == "sendmail"
puts "sending test email using sendmail..."
tmpfile = Tempfile.new("mail-test")
File.open(tmpfile.path, "w+") {|f| f << msgstr}
system("cat #{tmpfile.path} | sendmail -i -t") || exit(1)
else
smtp_authentication = ENV.fetch('SMTP_AUTHENTICATION', "none").to_sym
#set authentication to nil because :none is not supported by SMTP module
smtp_authentication = nil if smtp_authentication == :none
puts "sending test email using SMTP..."
Net::SMTP.start(
ENV.fetch('SMTP_HOST'),
ENV.fetch('SMTP_PORT'),
ENV.fetch('SMTP_DOMAIN'),
ENV.fetch('SMTP_USERNAME',nil),
ENV.fetch('SMTP_PASSWORD',nil),
smtp_authentication
) do |smtp|
smtp.send_message msgstr, from, admin_email
end
end