{"id":2580,"date":"2017-12-09T07:16:38","date_gmt":"2017-12-09T07:16:38","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2580"},"modified":"2020-01-09T07:53:32","modified_gmt":"2020-01-09T07:53:32","slug":"a-simple-ruby-method-to-send-email","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/a-simple-ruby-method-to-send-email\/","title":{"rendered":"A simple Ruby method to send email"},"content":{"rendered":"<p><strong>scmuser created the topic: A simple Ruby method to send email<\/strong><\/p>\n<p>A simple Ruby method to send email<\/p>\n<p>[code language=&#8221;css&#8221;]<br \/>\nrequire &#8216;net\/smtp&#8217;<\/p>\n<p>def send_email(to,opts={})<br \/>\nopts[:server]      ||= &#8216;localhost&#8217;<br \/>\nopts[:from]        ||= &#8217;email@example.com&#8217;<br \/>\nopts[:from_alias]  ||= &#8216;Example Emailer&#8217;<br \/>\nopts[:subject]     ||= &#8220;You need to see this&#8221;<br \/>\nopts[:body]        ||= &#8220;Important stuff!&#8221;<\/p>\n<p>msg = &lt;&lt;END_OF_MESSAGE<br \/>\nFrom: #{opts[:from_alias]} &lt;#{opts[:from]}&gt;<br \/>\nTo: &lt;#{to}&gt;<br \/>\nSubject: #{opts[:subject]}<\/p>\n<p>#{opts[:body]}<br \/>\nEND_OF_MESSAGE<\/p>\n<p>Net::SMTP.start(opts[:server]) do |smtp|<br \/>\nsmtp.send_message msg, opts[:from], to<br \/>\nend<br \/>\nend<\/p>\n<p>[\/code]<\/p>\n<p>send_email &#8220;admnistrator@example.com&#8221;, :body =&gt; &#8220;This was easy to send&#8221;<\/p>\n<p>Source &#8211; <a href=\"http:\/\/jerodsanto.net\/2009\/02\/a-simple-ruby-method-to-send-email\/\" target=\"_blank\" rel=\"noopener\">jerodsanto.net\/2009\/02\/a-simple-ruby-method-to-send-email\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>scmuser created the topic: A simple Ruby method to send email A simple Ruby method to send email [code language=&#8221;css&#8221;] require &#8216;net\/smtp&#8217; def send_email(to,opts={}) opts[:server] ||= &#8216;localhost&#8217; opts[:from] ||= &#8217;email@example.com&#8217; opts[:from_alias] ||= &#8216;Example Emailer&#8217; opts[:subject] ||= &#8220;You need to see this&#8221; opts[:body] ||= &#8220;Important stuff!&#8221; msg = &lt;&lt;END_OF_MESSAGE From: #{opts[:from_alias]} &lt;#{opts[:from]}&gt; To: &lt;#{to}&gt; Subject: #{opts[:subject]}&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[178],"class_list":["post-2580","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-ruby"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2580"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2580\/revisions"}],"predecessor-version":[{"id":8534,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2580\/revisions\/8534"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}