{"id":238,"date":"2024-01-26T10:02:32","date_gmt":"2024-01-26T10:02:32","guid":{"rendered":"https:\/\/mailmug.net\/blog\/?p=238"},"modified":"2024-01-29T03:48:06","modified_gmt":"2024-01-29T03:48:06","slug":"rust-send-email","status":"publish","type":"post","link":"https:\/\/mailmug.net\/blog\/rust-send-email\/","title":{"rendered":"Send Email With Rust &#8211; SMTP Or Sandbox SMTP"},"content":{"rendered":"\n<p>Send emails from the Rust program by using the SMTP library <strong><a href=\"https:\/\/docs.rs\/lettre\/latest\/lettre\/\">lettre<\/a><\/strong>.  The <strong>lettre<\/strong> rust crate is a powerful SMTP Rust library to send email. This library supports the async method. <\/p>\n\n\n\n<div style=\"height:39px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Navigate to specific topics instantly by clicking on the entries in the table of contents below.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#pain-html\">Sending a simple\u00a0<code>plain.txt<\/code>\u00a0email from Rust<\/a><\/li>\n\n\n\n<li><a href=\"#multiple-recipients\">Send emails to multiple recipients<\/a><\/li>\n\n\n\n<li><a href=\"#html-email\">HTML email from Rust<\/a><\/li>\n\n\n\n<li><a href=\"#attachment\">Send email with attachments<\/a><\/li>\n<\/ol>\n\n\n\n<div style=\"height:51px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pain-html\">Sending A Simple Plain-Text email from Rust<\/h2>\n\n\n\n<p>First, find SMTP sandbox credentials, Gmail SMTP credentials, or Purchase Commercial Email.<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/mailmug.net\/\">MailMug.net<\/a><\/strong> provides a free SMTP sandbox account. Sign up now then create an Inbox from the dashboard. <\/p>\n\n\n\n<p><strong><a href=\"https:\/\/mailmug.net\/\">Signup<\/a> &gt; Create Inbox &gt; Settings &gt; Click on Show credentials<\/strong>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials.png\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"262\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials.png\" alt=\"SMPT Sandbox account\" class=\"wp-image-75\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials.png 631w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/credentials-300x125.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:57px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-text-align-center\">OR<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending Email with Rust via Gmail<\/h2>\n\n\n\n<p>Google (Gmail) provides a free SMTP server. It needs to enable&nbsp;<a href=\"https:\/\/www.google.com\/landing\/2step\/\">two-step<strong> verification<\/strong><\/a>&nbsp;for your Gmail account.<\/p>\n\n\n\n<p>Next, generate an app password by following these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Visit your&nbsp;<strong><a href=\"https:\/\/myaccount.google.com\/\">Google account<\/a><\/strong>&nbsp;settings.<\/li>\n\n\n\n<li>Navigate to the&nbsp;<strong>Security<\/strong>&nbsp;section.<\/li>\n\n\n\n<li>Select&nbsp;<strong>2-Step Verification<\/strong>&nbsp;&gt;&nbsp;<strong>App passwords&nbsp;<\/strong>(bottom)<strong>.<\/strong><\/li>\n\n\n\n<li>Create a new app password.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"854\" height=\"224\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/app-password-gmail.png\" alt=\"smtp gmail password\" class=\"wp-image-216\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/app-password-gmail.png 854w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/app-password-gmail-300x79.png 300w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/12\/app-password-gmail-768x201.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/figure>\n\n\n\n<p>Now, input the credentials as outlined below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nHost: smtp.gmail.com\n \nUsername: youremail@gmail.com\n \nPassword: {app password}\n \nSecure(SSL)\n \nPort(465)\n<\/pre><\/div>\n\n\n<div style=\"height:57px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Example Send Email With Rust<\/h2>\n\n\n\n<p>Create the <strong>hello_mail<\/strong> project. Then install the SMTP library. Go to the project directory and enter the following command on the terminal. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncargo new  hello_mail --bin \ncd hello_mail\ncargo add lettre\n<\/pre><\/div>\n\n\n<p>Next, Add the following code to <strong>src\/main.rs<\/strong> file. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nuse lettre::{message::header::ContentType, Message, SmtpTransport, Transport};\n\nfn main() {\n\n    let email = Message::builder()\n        .from(&quot;nobody@domain.tld&quot;.parse().unwrap())\n        .reply_to(&quot;yuin@domain.tld&quot;.parse().unwrap())\n        .to(&quot;hei@domain.tld&quot;.parse().unwrap())\n        .subject(&quot;Happy new year&quot;)\n        .header(ContentType::TEXT_PLAIN)\n        .body(String::from(&quot;Be happy!&quot;))\n        .unwrap();\n\n    let username = &quot;username here&quot;;\n    let password = &quot;pass here&quot;;\n    let server = &quot;smtp.server.net&quot;;\n    let port = &quot;2525&quot;;\n    let url = format!(&quot;smtp:\/\/{username}:{password}@{server}:{port}&quot;);\n\n    let mailer =\n    SmtpTransport::from_url( &amp;url )\n        .unwrap().build();\n    \n    \/\/ Send the email\n    match mailer.send(&amp;email) {\n        Ok(_) =&gt; println!(&quot;Email sent successfully!&quot;),\n        Err(e) =&gt; panic!(&quot;Could not send email: {e:?}&quot;),\n    }\n}\n\n<\/pre><\/div>\n\n\n<p>Run the rust code. It will start to send. Now, you can see the email in the inbox.<\/p>\n\n\n\n<div style=\"height:62px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"multiple-recipients\">Send Emails To Multiple Recipients With Rust<\/h2>\n\n\n\n<p>Chaining <code>.to()<\/code>, <code>.cc()<\/code>, and <code>.bcc()<\/code> methods to send emails to multiple recipients. Each emails will added by parsing the string. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nuse lettre::{message::header::ContentType, Message, SmtpTransport, Transport};\n\nfn main() {\n\n    let email = Message::builder()\n        .from(&quot;nobody@domain.tld&quot;.parse().unwrap())\n        .reply_to(&quot;yuin@domain.tld&quot;.parse().unwrap())\n        .to(&quot;hei@domain.tld&quot;.parse().unwrap())\n        .to(&quot;to1@gmail.com&quot;.parse().unwrap())\n        .bcc(&quot;bcc@gmail.com&quot;.parse().unwrap())\n        .bcc(&quot;bcc2@gmail.com&quot;.parse().unwrap())\n        .cc(&quot;cc1@gmail.com&quot;.parse().unwrap())\n        .cc(&quot;cc@gmail.com&quot;.parse().unwrap())\n        .subject(&quot;Happy new year&quot;)\n        .header(ContentType::TEXT_PLAIN)\n        .body(String::from(&quot;Be happy!&quot;))\n        .unwrap();\n\n\n    let username = &quot;username here&quot;;\n    let password = &quot;pass&quot;;\n    let server = &quot;smtp.mailmug.net&quot;;\n    let port = &quot;2525&quot;;\n    let url = format!(&quot;smtp:\/\/{username}:{password}@{server}:{port}&quot;);\n\n    let mailer =\n    SmtpTransport::from_url( &amp;url )\n        .unwrap().build();\n    \n    \/\/ Send the email\n    match mailer.send(&amp;email) {\n        Ok(_) =&gt; println!(&quot;Email sent successfully!&quot;),\n        Err(e) =&gt; panic!(&quot;Could not send email: {e:?}&quot;),\n    }\n}\n\n<\/pre><\/div>\n\n\n<p><strong>Example Output<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/mail-inbox.png\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"436\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/mail-inbox.png\" alt=\"email to multiple recipients using Rust\" class=\"wp-image-249\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/mail-inbox.png 768w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/mail-inbox-300x170.png 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:73px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"html-email\">HTML Email From Rust<\/h2>\n\n\n\n<p>We need to set the body content type to <code>text\/html<\/code>. The <code>MultiPart<\/code> type represents a MIME multipart message, which is a message composed of multiple parts, each potentially of a different media type. The <code>SinglePart<\/code> type represents a MIME single-part message.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nuse lettre::{Message, SmtpTransport, Transport};\nuse lettre::message::{header, MultiPart, SinglePart};\n\nfn main() {\n\n    let email = Message::builder()\n        .from(&quot;nobody@domain.tld&quot;.parse().unwrap())\n        .reply_to(&quot;Yuin &lt;yuin@domain.tld&gt;&quot;.parse().unwrap())\n        .to(&quot;Hei &lt;hei@domain.tld&gt;&quot;.parse().unwrap())\n        .subject(&quot;Happy new year&quot;)\n        .multipart(\n            MultiPart::related()\n                .singlepart(\n                    SinglePart::builder()\n                        .header(header::ContentType::TEXT_HTML)\n                        .body(String::from(\n                            &quot;&lt;html&gt;\n                                &lt;body&gt;\n                                    &lt;h1&gt;Hello!&lt;\/h1&gt;\n                                    &lt;p&gt;This is a &lt;strong&gt;test mail&lt;\/strong&gt; from Rust Lang&lt;\/p&gt;\n                                &lt;\/body&gt;\n                            &lt;\/html&gt;&quot;,\n                        )),\n                )\n            ).unwrap();\n\n    let username = &quot;USER NAME&quot;;\n    let password = &quot;PASS&quot;;\n    let server = &quot;smtp.mailmug.net&quot;;\n    let port = &quot;2525&quot;;\n    let url = format!(&quot;smtp:\/\/{username}:{password}@{server}:{port}&quot;);\n\n    let mailer =\n    SmtpTransport::from_url( &amp;url )\n        .unwrap().build();\n    \n    \/\/ Send the email\n    match mailer.send(&amp;email) {\n        Ok(_) =&gt; println!(&quot;Email sent successfully!&quot;),\n        Err(e) =&gt; panic!(&quot;Could not send email: {e:?}&quot;),\n    }\n}\n\n<\/pre><\/div>\n\n\n<div style=\"height:53px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"attachment\">Send Emails With Attachments<\/h2>\n\n\n\n<p>Send emails attached file from Rust with <code>Attachment<\/code> struct. First, read file binary data and store it in a variable. Then create an image body with binary data. Eg: <code>Body::new(image)<\/code><\/p>\n\n\n\n<p>Then attached by <code>singlepart<\/code> method. You can send multiple files by chains of <code>singlepart<\/code>. <\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nuse lettre::{Message, SmtpTransport, Transport};\nuse lettre::message::{header, MultiPart, SinglePart, Body, Attachment};\nuse std::fs;\n\nfn main() {\n    let image_name = &quot;test.png&quot;;\n    let image: Vec&lt;u8&gt;= fs::read(&quot;test.png&quot;).unwrap(); \n    let image_body = Body::new(image);\n\n    let email = Message::builder()\n        .from(&quot;nobody@domain.tld&quot;.parse().unwrap())\n        .reply_to(&quot;Yuin &lt;yuin@domain.tld&gt;&quot;.parse().unwrap())\n        .to(&quot;Hei &lt;hei@domain.tld&gt;&quot;.parse().unwrap())\n        .subject(&quot;Happy new year&quot;)\n        .multipart(\n            MultiPart::related()\n                .singlepart(\n                    SinglePart::builder()\n                        .header(header::ContentType::TEXT_HTML)\n                        .body(String::from(\n                            &quot;&lt;html&gt;\n                                &lt;body&gt;\n                                    &lt;h1&gt;Hello!&lt;\/h1&gt;\n                                    &lt;p&gt;This is a &lt;strong&gt;test mail&lt;\/strong&gt; from Rust Lang&lt;\/p&gt;\n                                &lt;\/body&gt;\n                            &lt;\/html&gt;&quot;,\n                        )),\n                )\n                .singlepart(\n                    Attachment::new(image_name.to_string())\n                    .body(image_body, &quot;image\/png&quot;.parse().unwrap()),\n                )\n                \n            ).unwrap();\n\n    let username = &quot;username &quot;;\n    let password = &quot;pass&quot;;\n    let server = &quot;smtp.mailmug.net&quot;;\n    let port = &quot;2525&quot;;\n    let url = format!(&quot;smtp:\/\/{username}:{password}@{server}:{port}&quot;);\n\n    let mailer =\n    SmtpTransport::from_url( &amp;url )\n        .unwrap().build();\n    \n    \/\/ Send the email\n    match mailer.send(&amp;email) {\n        Ok(_) =&gt; println!(&quot;Email sent successfully!&quot;),\n        Err(e) =&gt; panic!(&quot;Could not send email: {e:?}&quot;),\n    }\n}\n\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Send emails from the Rust program by using the SMTP library lettre. The lettre rust crate is a powerful SMTP Rust library to send email. This library supports the async method. Navigate to specific topics instantly by clicking on the entries in the table of contents below. Sending A Simple Plain-Text email from Rust First, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":239,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smtp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog<\/title>\n<meta name=\"description\" content=\"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mailmug.net\/blog\/rust-send-email\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog\" \/>\n<meta property=\"og:description\" content=\"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mailmug.net\/blog\/rust-send-email\/\" \/>\n<meta property=\"og:site_name\" content=\"MailMug Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-26T10:02:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-29T03:48:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/rust-smtp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\"},\"headline\":\"Send Email With Rust &#8211; SMTP Or Sandbox SMTP\",\"datePublished\":\"2024-01-26T10:02:32+00:00\",\"dateModified\":\"2024-01-29T03:48:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/\"},\"wordCount\":363,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"articleSection\":[\"SMTP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mailmug.net\/blog\/rust-send-email\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/\",\"url\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/\",\"name\":\"Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#website\"},\"datePublished\":\"2024-01-26T10:02:32+00:00\",\"dateModified\":\"2024-01-29T03:48:06+00:00\",\"description\":\"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.\",\"breadcrumb\":{\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mailmug.net\/blog\/rust-send-email\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mailmug.net\/blog\/rust-send-email\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mailmug.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send Email With Rust &#8211; SMTP Or Sandbox SMTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mailmug.net\/blog\/#website\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"name\":\"MailMug\",\"description\":\"SandBox SMTP Email Account\",\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mailmug.net\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\",\"name\":\"MailMug\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"contentUrl\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"width\":320,\"height\":293,\"caption\":\"MailMug\"},\"image\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/mailmug.net\/blog\"],\"url\":\"https:\/\/mailmug.net\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog","description":"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mailmug.net\/blog\/rust-send-email\/","og_locale":"en_US","og_type":"article","og_title":"Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog","og_description":"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.","og_url":"https:\/\/mailmug.net\/blog\/rust-send-email\/","og_site_name":"MailMug Blog","article_published_time":"2024-01-26T10:02:32+00:00","article_modified_time":"2024-01-29T03:48:06+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2024\/01\/rust-smtp.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/#article","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/"},"author":{"name":"admin","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d"},"headline":"Send Email With Rust &#8211; SMTP Or Sandbox SMTP","datePublished":"2024-01-26T10:02:32+00:00","dateModified":"2024-01-29T03:48:06+00:00","mainEntityOfPage":{"@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/"},"wordCount":363,"commentCount":0,"publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"articleSection":["SMTP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mailmug.net\/blog\/rust-send-email\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/","url":"https:\/\/mailmug.net\/blog\/rust-send-email\/","name":"Send Email With Rust - SMTP Or Sandbox SMTP - MailMug Blog","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/#website"},"datePublished":"2024-01-26T10:02:32+00:00","dateModified":"2024-01-29T03:48:06+00:00","description":"Simple code to send email from rust. Send email by SMTP or Sandbox SMTP or Gmail. Configure HTML template to Email from rust.","breadcrumb":{"@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mailmug.net\/blog\/rust-send-email\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mailmug.net\/blog\/rust-send-email\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mailmug.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Send Email With Rust &#8211; SMTP Or Sandbox SMTP"}]},{"@type":"WebSite","@id":"https:\/\/mailmug.net\/blog\/#website","url":"https:\/\/mailmug.net\/blog\/","name":"MailMug","description":"SandBox SMTP Email Account","publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mailmug.net\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/mailmug.net\/blog\/#organization","name":"MailMug","url":"https:\/\/mailmug.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","contentUrl":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","width":320,"height":293,"caption":"MailMug"},"image":{"@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/mailmug.net\/blog"],"url":"https:\/\/mailmug.net\/blog\/author\/admin\/"}]}},"amp_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/238"}],"collection":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":13,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions\/265"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media\/239"}],"wp:attachment":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}