-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add script to send html emails to a local SMTP server
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
# This script will automatically send an HTML email to the | ||
# SMTP server given. | ||
|
||
require 'mail' | ||
require 'net/smtp' | ||
|
||
from = ARGV[0] | ||
to = ARGV[1] | ||
|
||
if from.nil? || to.nil? | ||
puts "Usage: ruby send-html-email.rb <from> <to>" | ||
exit 1 | ||
end | ||
|
||
|
||
mail = Mail.new | ||
mail.to = to | ||
mail.from = from | ||
mail.subject = "A test email from #{Time.now.to_s}" | ||
mail['X-Postal-Tag'] = 'send-html-email-script' | ||
mail.text_part = Mail::Part.new do | ||
body <<~BODY | ||
Hello there. | ||
This is an example. It doesn't do all that much. | ||
Some other characters: őúéáűí | ||
There is a link here through... https://postalserver.io/test-plain-text-link?foo=bar&baz=qux | ||
BODY | ||
end | ||
mail.html_part = Mail::Part.new do | ||
content_type 'text/html; charset=UTF-8' | ||
body <<~BODY | ||
<p>Hello there</p> | ||
<p>This is an example email. It doesn't do all that much.</p> | ||
<p>Some other characters: őúéáűí</p> | ||
<p>There is a <a href='https://postalserver.io/test-plain-text-link?foo=bar&baz=qux'>link here</a> though...</p> | ||
BODY | ||
end | ||
|
||
#puts mail.to_s | ||
|
||
Net::SMTP.start('127.0.0.1', 2525) do |smtp| | ||
smtp.send_message mail.to_s, mail.from.first, mail.to.first | ||
end | ||
|
||
puts "Sent" |