CINXE.COM
Ivan Djuric - Stack Abuse
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Ivan Djuric - Stack Abuse</title><link rel="canonical" href="https://stackabuse.com/author/ivan/"/><meta property="og:url" content="https://stackabuse.com/author/ivan/"/><meta name="twitter:url" content="https://stackabuse.com/author/ivan/"/><link rel="next" href="https://stackabuse.com/author/ivan/page/2/"/><meta property="og:site_name" content="Stack Abuse"/><meta property="og:type" content="profile"/><meta property="og:title" content="Ivan Djuric - Stack Abuse"/><meta name="twitter:card" content="summary"/><meta name="twitter:title" content="Ivan Djuric - Stack Abuse"/><meta name="twitter:site" content="@StackAbuse"/><script type="application/ld+json">{ "@context": "https://schema.org", "@type": "Person", "sameAs": [], "name": "Ivan Djuric", "url": "https://stackabuse.com/author/ivan/", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://stackabuse.com/" }, "image": { "@type": "ImageObject", "url": "https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg" } }</script><meta name="next-head-count" content="14"/><link href="//fonts.googleapis.com" rel="preconnect"/><link href="//fonts.gstatic.com" rel="preconnect" crossorigin="true"/><link href="//cdnjs.cloudflare.com" rel="preconnect"/><link href="//s3.stackabuse.com" rel="preconnect"/><link href="//googletagmanager.com" rel="dns-prefetch"/><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="HandheldFriendly" content="True"/><link rel="shortcut icon" sizes="any" href="/assets/images/favicon.ico"/><link rel="shortcut icon" type="image/svg+xml" href="/assets/images/favicon.svg"/><link rel="preload" as="style" href="//fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap"/><link rel="preload" as="style" href="//fonts.googleapis.com/css?family=Nunito:400,400i,700,700i&display=swap"/><meta name="referrer" content="no-referrer-when-downgrade"/><link rel="alternate" type="application/rss+xml" title="Stack Abuse" href="https://stackabuse.com/rss/"/><link rel="preload" href="/_next/static/css/eaee8aa5ba78cb00.css" as="style"/><link rel="stylesheet" href="/_next/static/css/eaee8aa5ba78cb00.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="/_next/static/chunks/webpack-be96297a301ce438.js" defer=""></script><script src="/_next/static/chunks/framework-1dabaad0401a053e.js" defer=""></script><script src="/_next/static/chunks/main-1b53524783caa372.js" defer=""></script><script src="/_next/static/chunks/pages/_app-85dd70c54f224ed0.js" defer=""></script><script src="/_next/static/chunks/c78d26b1-fe043233b220ebfb.js" defer=""></script><script src="/_next/static/chunks/816-dfcc5ef3cff7cadb.js" defer=""></script><script src="/_next/static/chunks/3646-f084444085f451b1.js" defer=""></script><script src="/_next/static/chunks/7329-ea47eb245049fa3f.js" defer=""></script><script src="/_next/static/chunks/2221-aa293f4e0cf5d5c8.js" defer=""></script><script src="/_next/static/chunks/pages/author/%5B...slug%5D-9a0a529e41423fb6.js" defer=""></script><script src="/_next/static/1740324887682/_buildManifest.js" defer=""></script><script src="/_next/static/1740324887682/_ssgManifest.js" defer=""></script></head><body><div id="__next"><div><nav class="bg-white pb-2 border-b shadow"><div class="mx-8 px-2 sm:px-4 lg:px-8"><div class="flex justify-between h-16"><div class="flex items-center px-2 lg:px-0"><a href="/"><div class="flex-shrink-0 flex items-center"><svg class="h-6 w-full" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 494.36 63"><defs><style>.cls-1{fill:#363636}.cls-2{fill:#f29c80}.cls-3{fill:#b34a28}.cls-4{fill:#f16335}</style></defs><title>SA Logotype</title><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M104.94,27.65q-3.15-1.44-4.65-2.16c-1-.48-2.17-1.12-3.49-1.91A10.35,10.35,0,0,1,94,21.35a3.58,3.58,0,0,1-.82-2.27,4.79,4.79,0,0,1,1.74-3.89,7.6,7.6,0,0,1,5-1.44,16,16,0,0,1,5.61,1.15,27.13,27.13,0,0,1,4.1,1.84c.73.46,1.3.83,1.71,1.12l5.2-10.8-2-1.44A28.63,28.63,0,0,0,108,2.84a29.37,29.37,0,0,0-9-1.4A18.5,18.5,0,0,0,86.2,6.52a16.81,16.81,0,0,0-5.61,13.06,14.64,14.64,0,0,0,2.81,8.61,21.59,21.59,0,0,0,7.93,6.66c.82.43,2.09,1.07,3.8,1.91s2.94,1.46,3.69,1.87a27.75,27.75,0,0,1,2.6,1.65,6.9,6.9,0,0,1,2,2.09,4.57,4.57,0,0,1,.58,2.27q0,5.84-8.14,5.83a14.52,14.52,0,0,1-6.46-1.87,35.41,35.41,0,0,1-5.1-3c-.95-.74-1.71-1.35-2.25-1.83L75.67,55.15l.89.79a19.23,19.23,0,0,0,2.8,2c1.28.77,2.71,1.55,4.31,2.34a26.52,26.52,0,0,0,6,2,33.14,33.14,0,0,0,7.25.79,29.54,29.54,0,0,0,8-1,21.94,21.94,0,0,0,6.74-3.21,14.53,14.53,0,0,0,4.79-6,21.36,21.36,0,0,0,1.74-8.93,13.77,13.77,0,0,0-3.86-9.54A28,28,0,0,0,104.94,27.65Z"></path><path class="cls-1" d="M143.66,50.69a5.8,5.8,0,0,1-1.17.57,3.84,3.84,0,0,1-1.43.29q-2.75,0-2.74-5.11V34.7h7.39V25h-7.39V11.23H126.21V25h-5.06V34.7h5.06V48.89a22.21,22.21,0,0,0,.55,5,16,16,0,0,0,1.81,4.47,9,9,0,0,0,3.73,3.38A12.76,12.76,0,0,0,138.18,63a17.23,17.23,0,0,0,8.9-2.3l-3-10.3Z"></path><path class="cls-1" d="M177.44,28.51A15.41,15.41,0,0,0,166,23.9a15.82,15.82,0,0,0-12.51,5.69,20.47,20.47,0,0,0-4.93,13.9,20.33,20.33,0,0,0,4.93,13.86A15.85,15.85,0,0,0,166,63a14.47,14.47,0,0,0,11.49-5.26h.14v4.18h12V25H177.44Zm-2,21.17a7.68,7.68,0,0,1-5.85,2.45,7.79,7.79,0,0,1-6-2.41,8.74,8.74,0,0,1-2.26-6.23,8.69,8.69,0,0,1,2.36-6.27,8.15,8.15,0,0,1,11.63,0,8.69,8.69,0,0,1,2.36,6.27A8.74,8.74,0,0,1,175.43,49.68Z"></path><path class="cls-1" d="M216.43,34.34a9.4,9.4,0,0,1,5.88,1.73l4.11-8.71-1.16-.86a15,15,0,0,0-4.18-1.73,22.57,22.57,0,0,0-6.43-.87,18.72,18.72,0,0,0-13.57,5.8,18.81,18.81,0,0,0-5.85,13.86,18.52,18.52,0,0,0,5.85,13.72A18.83,18.83,0,0,0,214.65,63a22,22,0,0,0,6.54-.94,20,20,0,0,0,3.89-1.47c.57-.36,1-.66,1.34-.9l-4.11-8.86-.61.43a9.12,9.12,0,0,1-2.16.87,10.87,10.87,0,0,1-3.11.43,7.75,7.75,0,0,1-5.88-2.66,9.22,9.22,0,0,1-2.46-6.48A9.1,9.1,0,0,1,210.55,37,7.72,7.72,0,0,1,216.43,34.34Z"></path><polygon class="cls-1" points="271.43 24.98 255.69 24.98 243.45 37.87 243.45 0 231.34 0 231.34 61.92 243.45 61.92 243.45 47.16 257.47 61.92 273.07 61.92 254.74 42.62 271.43 24.98"></polygon><polygon class="cls-1" points="296.96 2.52 274.18 61.92 288 61.92 302.84 20.88 302.98 20.88 317.82 61.92 331.63 61.92 308.86 2.52 296.96 2.52"></polygon><path class="cls-1" d="M357.42,23.9a15.41,15.41,0,0,0-11.49,4.61V0H333.82V61.92h12V57.74h.14A14.47,14.47,0,0,0,357.42,63a15.88,15.88,0,0,0,12.52-5.65,20.38,20.38,0,0,0,4.92-13.86,20.51,20.51,0,0,0-4.92-13.9A15.86,15.86,0,0,0,357.42,23.9Zm2.33,25.82a7.8,7.8,0,0,1-5.95,2.41A7.65,7.65,0,0,1,348,49.68a8.69,8.69,0,0,1-2.29-6.19A8.64,8.64,0,0,1,348,37.22a7.7,7.7,0,0,1,5.78-2.44,7.78,7.78,0,0,1,5.84,2.44A8.64,8.64,0,0,1,362,43.49,8.78,8.78,0,0,1,359.75,49.72Z"></path><path class="cls-1" d="M405.78,42.55c0,3.65-.53,6.24-1.57,7.78s-2.83,2.3-5.34,2.3-4.29-.77-5.33-2.3S392,46.2,392,42.55V25h-12.1V45.65q0,9.21,4.54,13.28T398.87,63q9.92,0,14.47-4.07t4.55-13.28V25H405.78Z"></path><path class="cls-1" d="M449.11,42.19A20.21,20.21,0,0,0,445.79,40a23.31,23.31,0,0,0-3.69-1.44,8.7,8.7,0,0,1-1-.29c-.44-.14-.74-.25-.93-.32l-.82-.32-.78-.33-.65-.32a2.25,2.25,0,0,1-.58-.4c-.12-.12-.24-.26-.38-.43a1.25,1.25,0,0,1-.27-.54,2.25,2.25,0,0,1-.07-.58,1.82,1.82,0,0,1,.85-1.76,6.53,6.53,0,0,1,2.91-.47,16,16,0,0,1,7.8,2.31l4-8.36-1.43-.72a22.21,22.21,0,0,0-4.38-1.44,24.9,24.9,0,0,0-5.95-.72q-7,0-11.18,3.14a10.32,10.32,0,0,0-4.14,8.74,9.07,9.07,0,0,0,1.91,6,18.12,18.12,0,0,0,5.2,4.06,28.82,28.82,0,0,0,3.59,1.59A14.8,14.8,0,0,1,439,49a2.2,2.2,0,0,1,1,1.9c0,1.78-1.26,2.67-3.76,2.67a9.22,9.22,0,0,1-4-1.19A23.33,23.33,0,0,1,429,50.51c-.6-.46-1.08-.85-1.44-1.19L422.61,58l1.5,1.3A17.63,17.63,0,0,0,429,61.78,21,21,0,0,0,436.15,63q16.62,0,16.62-12.6a11.23,11.23,0,0,0-1-4.75A9.24,9.24,0,0,0,449.11,42.19Z"></path><path class="cls-1" d="M494.36,43.49q0-9.43-5.24-14.51T475.55,23.9a18.46,18.46,0,0,0-13.62,5.76,19,19,0,0,0-5.67,13.83,18.9,18.9,0,0,0,5.67,13.79A18.54,18.54,0,0,0,475.55,63q12.72,0,18.19-9.65L485,48.74a13.63,13.63,0,0,1-3.9,3.28,10.84,10.84,0,0,1-4.65.83,8.3,8.3,0,0,1-5.2-1.87q-2.4-1.87-2.4-5.76h25.45A14.91,14.91,0,0,0,494.36,43.49Zm-25.17-5.33a6,6,0,0,1,1.91-4.32,6.77,6.77,0,0,1,4.79-1.66,6.51,6.51,0,0,1,4.48,1.55,7,7,0,0,1,2.15,4.43Z"></path><polygon class="cls-2" points="66.05 19.08 73.15 1.3 57.25 1.3 50.16 19.08 66.05 19.08"></polygon><polygon class="cls-3" points="40.21 43.99 32.99 62.06 48.88 62.06 56.1 43.99 40.21 43.99"></polygon><polygon class="cls-4" points="57.69 40.01 64.46 23.05 48.57 23.05 41.8 40.01 57.69 40.01"></polygon><polygon class="cls-2" points="33.06 19.08 40.16 1.3 24.27 1.3 17.17 19.08 33.06 19.08"></polygon><polygon class="cls-3" points="7.22 43.99 0 62.06 15.89 62.06 23.11 43.99 7.22 43.99"></polygon><polygon class="cls-4" points="24.7 40.01 31.47 23.05 15.58 23.05 8.81 40.01 24.7 40.01"></polygon></g></g></svg></div></a><div class="hidden lg:block lg:ml-6"><div class="hidden lg:ml-6 lg:flex"><a href="/tools/" class="mr-8 inline-flex items-center px-1 pt-1 border-b-2 border-blue-400 text-sm font-medium leading-10 text-gray-500 hover:text-gray-700 focus:outline-none focus:text-gray-700 transition duration-150 ease-in-out">Tools</a><div class="px-1 pt-1 border-b-2 border-green-400 focus:border-gray-300 transition duration-150 ease-in-out"><div class="relative" data-headlessui-state=""><button class="text-gray-500 group rounded-md inline-flex items-center focus:outline-none text-sm font-medium leading-10 text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700" type="button" aria-expanded="false" data-headlessui-state=""><span>Learn</span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="text-gray-400 ml-2 h-5 w-5 group-hover:text-gray-500"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></button></div><div hidden="" style="position:fixed;top:1px;left:1px;width:1px;height:0;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0;display:none"></div></div><a href="/about/" class="ml-8 inline-flex items-center px-1 pt-1 border-b-2 border-red-400 text-sm font-medium leading-10 text-gray-500 hover:text-gray-700 focus:outline-none focus:text-gray-700 transition duration-150 ease-in-out">About</a></div></div></div><div class="hidden mt-4 md:flex md:flex-1 md:items-center md:justify-center md:px-2 lg:ml-6 lg:justify-end"><div class="relative w-1/2 text-gray-400 transition duration-200 focus-within:text-gray-600"><div class="absolute inset-y-0 left-0 flex items-center pointer-events-none" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="h-5 w-5 ml-2"><path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd"></path></svg></div><input id="search-field" class="block w-full h-full pl-10 pr-3 py-3 text-sm border-gray-300 text-gray-900 placeholder-gray-500 rounded transition duration-200 focus:outline-none focus:ring-0 focus:border-gray-400" placeholder="Search" type="text"/></div><div class="hidden ml-6 md:flex items-center"><button class="whitespace-nowrap text-base font-medium text-gray-500 hover:text-gray-900">Sign in</button><button class="ml-6 whitespace-nowrap inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-base font-medium text-white bg-orange-500 hover:bg-orange-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500">Sign up</button></div></div><div class="flex items-center lg:hidden"><button class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500 transition duration-150 ease-in-out" aria-label="Main menu" aria-expanded="false"><svg class="block h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg><svg class="hidden h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg></button></div></div></div><div class="hidden lg:hidden"><div class="pt-2 pb-3"><a href="/tag/python" class="mt-1 block pl-3 pr-4 py-2 border-l-4 border-transparent text-base font-medium text-gray-600 hover:text-gray-800 hover:bg-gray-50 hover:border-gray-300 focus:outline-none focus:text-gray-800 focus:bg-gray-50 focus:border-gray-300 transition duration-150 ease-in-out">Python</a><a href="/tag/javascript" class="mt-1 block pl-3 pr-4 py-2 border-l-4 border-transparent text-base font-medium text-gray-600 hover:text-gray-800 hover:bg-gray-50 hover:border-gray-300 focus:outline-none focus:text-gray-800 focus:bg-gray-50 focus:border-gray-300 transition duration-150 ease-in-out">JavaScript</a><a href="/tag/java" class="mt-1 block pl-3 pr-4 py-2 border-l-4 border-transparent text-base font-medium text-gray-600 hover:text-gray-800 hover:bg-gray-50 hover:border-gray-300 focus:outline-none focus:text-gray-800 focus:bg-gray-50 focus:border-gray-300 transition duration-150 ease-in-out">Java</a></div></div></nav><main><div class="flex items-stretch min-h-screen"><div class="mx-auto max-w-none lg:max-w-screen-xl px-4 sm:px-6 pb-6"><div class="grid grid-cols-12 sm:gap-x-2 lg:gap-x-3 pt-6"><div class="col-span-12 lg:col-span-3"><img class="object-cover shadow-lg rounded-lg h-60 w-60" src="https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg" alt="Ivan Djuric"/><div class="inline-flex py-4"></div></div><div class="col-span-12 lg:col-span-7"><h1 class="my-1 text-3xl tracking-tight leading-10 font-extrabold text-gray-900 sm:leading-none sm:text-6xl lg:text-4xl xl:text-5xl">Ivan Djuric</h1><div class="">Articles: <!-- -->2</div><div class="">Joined: <!-- -->Aug 21, 2024</div><div class="my-4"><p>I鈥檓 a Technical Content Writer with 5 years of background covering email-related topics in tight collaboration with software engineers and email marketers. I just love to research and share actionable insights with you about email sending, testing, deliverability improvements, and more. Happy to be your guide in the world of emails!</p> </div></div><div class="lg:col-span-1"></div></div><div class="mt-8 border-t border-gray-200"><h2 class="my-6 text-xl tracking-tight leading-10 font-extrabold text-gray-700 sm:leading-none sm:text-4xl lg:text-2xl xl:text-3xl">Recently published</h2><div class="grid gap-5 lg:grid-cols-3"><div><div class="flex flex-col rounded-lg shadow-lg overflow-hidden"><div class="flex-shrink-0"><a href="/securing-your-email-sending-with-python-authentication-and-encryption/"><img class="h-48 w-full object-cover" src="/assets/images/logo-python.png" alt=""/></a></div><div class="flex-1 bg-white p-6 flex flex-col justify-between"><div class="flex-1"><p class="text-sm leading-5 font-medium text-primary">Article</p><a class="block hover:no-underline" href="/securing-your-email-sending-with-python-authentication-and-encryption/"><h3 class="mt-2 text-xl leading-7 font-semibold text-gray-900 hover:underline">Securing Your Email Sending With Python: Authentication and Encryption</h3><p class="mt-3 text-base leading-6 text-gray-500 break-words">Email encryption and authentication are modern security techniques that you can use to protect your emails and their content from unauthorized access. Everyone, from individuals to business owners, uses emails for official communication, which may contain sensitive information. Therefore, securing emails is important, especially when cyberattacks like phishing, smishing, etc....</p></a></div><div class="mt-6 flex items-center"><div class="flex-shrink-0"><a href="/author/ivan/"><img class="h-10 w-10 rounded-full" src="https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg" alt="Ivan Djuric"/></a></div><div class="ml-3"><p class="text-sm leading-5 font-medium text-gray-900"><a href="/author/ivan/" class="hover:underline">Ivan Djuric</a></p><div class="flex text-sm leading-5 text-gray-500"><time dateTime="2024-09-19">Sep 19, 2024</time><span class="mx-1">路</span><span>19<!-- --> min read</span></div></div></div></div></div></div><div><div class="flex flex-col rounded-lg shadow-lg overflow-hidden"><div class="flex-shrink-0"><a href="/building-custom-email-templates-with-html-and-css-in-python/"><div class="lazyload-wrapper "><div style="height:12rem" class="lazyload-placeholder"></div></div></a></div><div class="flex-1 bg-white p-6 flex flex-col justify-between"><div class="flex-1"><p class="text-sm leading-5 font-medium text-primary">Article</p><a class="block hover:no-underline" href="/building-custom-email-templates-with-html-and-css-in-python/"><h3 class="mt-2 text-xl leading-7 font-semibold text-gray-900 hover:underline">Building Custom Email Templates with HTML and CSS in Python</h3><p class="mt-3 text-base leading-6 text-gray-500 break-words">An HTML email utilizes HTML code for presentation. Its design is heavy and looks like a modern web page, rich with visual elements like images, videos, etc., to emphasize different parts of an email's content. Building email templates tailored to your brand is useful for various email marketing purposes such...</p></a></div><div class="mt-6 flex items-center"><div class="flex-shrink-0"><a href="/author/ivan/"><div class="lazyload-wrapper "><div style="height:2.5rem" class="lazyload-placeholder"></div></div></a></div><div class="ml-3"><p class="text-sm leading-5 font-medium text-gray-900"><a href="/author/ivan/" class="hover:underline">Ivan Djuric</a></p><div class="flex text-sm leading-5 text-gray-500"><time dateTime="2024-08-20">Aug 20, 2024</time><span class="mx-1">路</span><span>19<!-- --> min read</span></div></div></div></div></div></div></div><div class="mt-8 border-t border-gray-200 px-4 flex items-center justify-between sm:px-0"></div></div></div></div></main><div class="bg-white border-t border-gray-300"><div class="max-w-screen-xl mx-auto pt-12 pb-6 px-4 sm:px-6 md:flex md:items-center md:justify-between lg:px-8"><div class="flex justify-center md:order-2"><a href="https://twitter.com/stackabuse" target="_blank" rel="noreferrer noopener" class="text-gray-500 hover:text-twitter"><span class="sr-only">Twitter</span><svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24"><path d="M8.29 20.251c7.547 0 11.675-6.253 11.675-11.675 0-.178 0-.355-.012-.53A8.348 8.348 0 0022 5.92a8.19 8.19 0 01-2.357.646 4.118 4.118 0 001.804-2.27 8.224 8.224 0 01-2.605.996 4.107 4.107 0 00-6.993 3.743 11.65 11.65 0 01-8.457-4.287 4.106 4.106 0 001.27 5.477A4.072 4.072 0 012.8 9.713v.052a4.105 4.105 0 003.292 4.022 4.095 4.095 0 01-1.853.07 4.108 4.108 0 003.834 2.85A8.233 8.233 0 012 18.407a11.616 11.616 0 006.29 1.84"></path></svg></a><a href="https://github.com/stackabuse" target="_blank" rel="noreferrer noopener" class="ml-6 text-gray-500 hover:text-github"><span class="sr-only">GitHub</span><svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg></a><a href="https://www.facebook.com/stackabuse" target="_blank" rel="noreferrer noopener" class="ml-6 text-gray-500 hover:text-facebook"><span class="sr-only">Facebook</span><svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M22 12c0-5.523-4.477-10-10-10S2 6.477 2 12c0 4.991 3.657 9.128 8.438 9.878v-6.987h-2.54V12h2.54V9.797c0-2.506 1.492-3.89 3.777-3.89 1.094 0 2.238.195 2.238.195v2.46h-1.26c-1.243 0-1.63.771-1.63 1.562V12h2.773l-.443 2.89h-2.33v6.988C18.343 21.128 22 16.991 22 12z" clip-rule="evenodd"></path></svg></a></div><div class="mt-8 md:mt-0 md:order-1"><p class="text-center text-base leading-6 text-gray-500">漏 2013-<!-- -->2025<!-- --> Stack Abuse. All rights reserved.</p><div class="text-sm"><a href="/about" class="pr-4 text-gray-500 border-r-2 border-grey-400 hover:no-underline hover:text-gray-600">About</a><a href="/disclosure" class="px-4 text-gray-500 border-r-2 border-grey-400 hover:no-underline hover:text-gray-600">Disclosure</a><a href="/privacy-policy" class="px-4 text-gray-500 border-r-2 border-grey-400 hover:no-underline hover:text-gray-600">Privacy</a><a href="/terms-of-service" class="pl-4 text-gray-500 hover:no-underline hover:text-gray-600">Terms</a><div id="ccpa" style="display:none;cursor:pointer">Do not share my Personal Information.</div></div></div></div></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"author":{"id":26126,"name":"Ivan Djuric","slug":"ivan","role_id":null,"img_profile":"https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg","img_cover":null,"bio_html":"\u003cp\u003eI鈥檓 a Technical Content Writer with 5 years of background covering email-related topics in tight collaboration with software engineers and email marketers. I just love to research and share actionable insights with you about email sending, testing, deliverability improvements, and more. Happy to be your guide in the world of emails!\u003c/p\u003e\n","website":null,"location":null,"facebook":null,"twitter":null,"github":null,"created_at":1724257087195,"updated_at":1724257803744,"role":"contributor","contents":[{"id":2134,"title":"Securing Your Email Sending With Python: Authentication and Encryption","slug":"securing-your-email-sending-with-python-authentication-and-encryption","body_html":"\u003cp\u003eEmail encryption and authentication are modern security techniques that you can use to protect your emails and their content from unauthorized access.\u003c/p\u003e\n\u003cp\u003eEveryone, from individuals to business owners, uses emails for official communication, which may contain sensitive information. Therefore, securing emails is important, especially when cyberattacks like phishing, smishing, etc. are soaring high.\u003c/p\u003e\n\u003cp\u003eIn this article, I'll discuss how to send emails in Python securely using \u003cstrong\u003eemail encryption\u003c/strong\u003e and authentication.\u003c/p\u003e\n\u003ch2 id=\"settingupyourpythonenvironment\"\u003eSetting Up Your Python Environment\u003c/h2\u003e\n\u003cp\u003eBefore you start creating the code for sending emails, set up your Python environment first with the configurations and libraries you'll need.\u003c/p\u003e\n\u003cp\u003eYou can send emails in Python using:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSimple Mail Transfer Protocol (SMTP):\u003c/strong\u003e This application-level protocol simplifies the process since Python offers an in-built library or module (\u003ccode\u003esmtplib\u003c/code\u003e) for sending emails. It's suitable for businesses of all sizes as well as individuals to automate \u003cstrong\u003esecure email sending in Python\u003c/strong\u003e. We're using the Gmail \u003cstrong\u003eSMTP service\u003c/strong\u003e in this article.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eAn email API\u003c/strong\u003e: You can leverage a third-party API like Mailtrap Python SDK, SendGrid, Gmail API, etc., to dispatch emails in Python. This method offers more features and high email delivery speeds, although it requires some investment.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn this tutorial, we're opting for the first choice - sending emails in Python using SMTP, facilitated by the \u003ccode\u003esmtplib\u003c/code\u003e library. This library uses the RFC 821 protocol and interacts with SMTP and mail servers to streamline email dispatch from your applications. Additionally, you should install packages to enable \u003cstrong\u003ePython email encryption\u003c/strong\u003e, authentication, and formatting.\u003c/p\u003e\n\u003ch3 id=\"step1installpython\"\u003eStep 1: Install Python\u003c/h3\u003e\n\u003cp\u003eInstall the Python programming language on your computer (Windows, macOS, Linux, etc.). You can visit the \u003ca href=\"https://www.python.org/downloads/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eofficial Python website\u003c/a\u003e and download and install it from there.\u003c/p\u003e\n\u003cp\u003eIf you've already installed it, run this code to verify it:\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003epython --version\u003c/code\u003e\u003c/p\u003e\n\u003ch3 id=\"step2installnecessarymodulesandlibraries\"\u003eStep 2: Install Necessary Modules and Libraries\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003esmtplib\u003c/code\u003e: This handles SMTP communications. Use the code below to import 'smtplib' and connect with your email server:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003eemail\u003c/code\u003e module: This provides classes (Subject, To, From, etc.) to construct and parse emails. It also facilitates email encoding and decoding with Multipurpose Internet Mail Extensions (MIME).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003eMIMEText\u003c/code\u003e: It's used for formatting your emails and supports sending emails with text and attachments like images, videos, etc. Import this using the code below:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEText\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eMIMEMultipart: Use this library to add attachments and text sections separately in your email.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEMultipart\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003essl\u003c/code\u003e: It provides Secure Sockets Layer (SSL) encryption.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"step3createagmailaccount\"\u003eStep 3: Create a Gmail Account\u003c/h3\u003e\n\u003cp\u003eTo send emails using the Gmail \u003ca href=\"https://mailtrap.io/smtp-service/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eSMTP email service\u003c/a\u003e, I recommend creating a test account to develop the code. Delete the account once you've tested the code.\u003c/p\u003e\n\u003cp\u003eThe reason is, you'll need to modify the security settings of your Gmail account to enable access from the Python code for sending emails. This might expose the login details, compromising security. In addition, it will flood your account with too many test emails.\u003c/p\u003e\n\u003cp\u003eSo, instead of using your own Gmail account, create a new one for creating and testing the code. Here's how to do this:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eCreate a fresh Gmail account\u003c/li\u003e\n\u003cli\u003eSet up your app password:\u003cbr\u003e\n\u003ccode\u003eGoogle Account \u0026gt; Security \u0026gt; Turn on 2-Step Verification \u0026gt; Security \u0026gt; Set up an App Password\u003c/code\u003e\u003cbr\u003e\nNext, define a name for the app password and click on \u0026quot;Generate\u0026quot;. You'll get a 16-digit password after following some instructions on the screen. Store the password safely.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eUse this password while sending emails in Python. Here, we're using Gmail SMTP, but if you want to use another mail service provider, follow the same process. Alternatively, contact your company's IT team to seek support in accessing your SMTP server.\u003c/p\u003e\n\u003ch2 id=\"emailauthenticationwithpython\"\u003eEmail Authentication With Python\u003c/h2\u003e\n\u003cp\u003eEmail authentication is a security mechanism that verifies the sender's identity, ensuring the emails from a domain are legitimate. If you have no email authentication mechanism in place, your emails might land in spam folders, or malicious actors can spoof or intercept them. This could affect your email delivery rates and the sender's reputation.\u003c/p\u003e\n\u003cp\u003eThis is the reason you must enable \u003cstrong\u003ePython email authentication\u003c/strong\u003e mechanisms and protocols, such as:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSMTP authentication\u003c/strong\u003e: If you're sending emails using an SMTP server like Gmail SMTP, you can use this method of authentication. It verifies the sender's authenticity when sending emails via a specific mail server.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSPF\u003c/strong\u003e: Stands for Sender Policy Framework and checks whether the IP address of the sending server is among\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eDKIM\u003c/strong\u003e: Stands for DomainKeys Identified Mail and is used to add a digital signature to emails to ensure no one can alter the email's content while it's in transmission. The receiver's server will then verify the digital signature. Thus, all your emails and their content stay secure and unaltered.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eDMARC\u003c/strong\u003e: Stands for Domain-based Message Authentication, Reporting, and Conformance. DMARC instructs mail servers what to do if an email fails authentication. In addition, it provides reports upon detecting any suspicious activities on your domain.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"howtoimplementemailauthenticationinpython\"\u003eHow to Implement Email Authentication in Python\u003c/h3\u003e\n\u003cp\u003eTo authenticate your email in Python using SMTP, the \u003ccode\u003esmtplib\u003c/code\u003e library is useful. Here's how \u003cstrong\u003ePython SMTP security\u003c/strong\u003e works:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\nserver = smtplib.SMTP(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e587\u003c/span\u003e)\nserver.starttls() \u003cspan class=\"hljs-comment\"\u003e# Start TLS for secure connection\u003c/span\u003e\nserver.login(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_password\u0026#x27;\u003c/span\u003e)\n\nmessage = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Subject: Test Email.\u0026quot;\u003c/span\u003e\nserver.sendmail(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;receiver@domain2.com\u0026#x27;\u003c/span\u003e, message)\n\nserver.quit()\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eImplementing email authentication will add an additional layer of security to your emails and protect them from attackers or from being marked as spam.\u003c/p\u003e\n\u003ch2 id=\"encryptingemailswithpython\"\u003eEncrypting Emails With Python\u003c/h2\u003e\n\u003cp\u003eEncrypting emails enables you to protect your email's content so that only authorized senders and receivers can access or view the content. \u003cstrong\u003eEncrypting emails with Python\u003c/strong\u003e is done using encryption techniques to encode the email message and transform it into a secure and unreadable format (also known as ciphertext).\u003c/p\u003e\n\u003cp\u003eThis way, email encryption secures the message from unauthorized access or attackers even if they intercept the email.\u003c/p\u003e\n\u003cp\u003eHere are different \u003ca href=\"https://mailtrap.io/blog/email-encryption/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003etypes of email encryption\u003c/a\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSSL:\u003c/strong\u003e This stands for Secure Sockets Layer, one of the most popular and widely used encryption protocols. SSL ensures email confidentiality by encrypting data transmitted between the mail server and the client.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eTLS:\u003c/strong\u003e This stands for Transport Layer Security and is a common email encryption protocol today. Many consider it a great alternative to SSL. It encrypts the connection between an email client and the mail server to prevent anyone from intercepting the email during its transmission.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eE2EE:\u003c/strong\u003e This stands for end-to-end encryption, ensuring only the intended recipient with valid credentials can decrypt the email content and read it. It aims to prevent email interception and secure the message.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"howtoimplementemailencryptioninpython\"\u003eHow to Implement Email Encryption in Python\u003c/h3\u003e\n\u003cp\u003eIf your mail server requires SSL encryption, here's \u003ca href=\"https://stackabuse.com/how-to-send-an-email-with-boto-and-ses/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003ehow to send an email in Python\u003c/a\u003e:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e ssl\n\ncontext = ssl.create_default_context()\n\nserver = smtplib.SMTP_SSL(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e465\u003c/span\u003e, context=context) \u003cspan class=\"hljs-comment\"\u003e# This is for SSL connections, requiring port number 465\u003c/span\u003e\nserver.login(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_password\u0026#x27;\u003c/span\u003e)\n\nmessage = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Subject: SSL Encrypted Email.\u0026quot;\u003c/span\u003e\nserver.sendmail(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;receiver@domain2.com\u0026#x27;\u003c/span\u003e, message)\n\nserver.quit()\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eFor TLS connections\u003c/strong\u003e, you'll need the \u003ccode\u003esmtplib\u003c/code\u003e library:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\nserver = smtplib.SMTP(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e587\u003c/span\u003e) \u003cspan class=\"hljs-comment\"\u003e# TLS requires 587 port number\u003c/span\u003e\nserver.starttls() \u003cspan class=\"hljs-comment\"\u003e# Start TLS encryption\u003c/span\u003e\nserver.login(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_password\u0026#x27;\u003c/span\u003e)\n\nmessage = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Subject: TLS Encrypted Email.\u0026quot;\u003c/span\u003e\nserver.sendmail(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;my_email@domain1.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;receiver@domain2.com\u0026#x27;\u003c/span\u003e, message)\n\nserver.quit()\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eFor end-to-end encryption, you'll need more advanced libraries or tools such as GnuPG, OpenSSL, Signal Protocol, and more.\u003c/p\u003e\n\u003ch2 id=\"combiningauthenticationandencryption\"\u003eCombining Authentication and Encryption\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003eEmail Security with Python\u003c/strong\u003e requires both encryption and authentication. This ensures that mail servers find the email legitimate and it stays safe from cyber attackers and unauthorized access during transmission. For email encryption, you can use either SSL or TLS and combine it with SMTP authentication to establish a robust email connection.\u003c/p\u003e\n\u003cp\u003eNow that you know how to enable email encryption and authentication in your emails, let's examine some complete code examples to understand how you can send secure emails in Python using Gmail SMTP and email encryption (SSL).\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eCode Examples\u003c/strong\u003e\u003c/p\u003e\n\u003ch3 id=\"1sendingaplaintextemail\"\u003e1. Sending a Plain Text Email\u003c/h3\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.text \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEText\n\nsubject = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Plain Text Email\u0026quot;\u003c/span\u003e\nbody = \u003cspan class=\"hljs-string\"\u003e\u0026quot;This is a plain text email using Gmail SMTP and SSL.\u0026quot;\u003c/span\u003e\nsender = \u003cspan class=\"hljs-string\"\u003e\u0026quot;sender1@gmail.com\u0026quot;\u003c/span\u003e\nreceivers = [\u003cspan class=\"hljs-string\"\u003e\u0026quot;receiver1@gmail.com\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026quot;receiver2@gmail.com\u0026quot;\u003c/span\u003e]\npassword = \u003cspan class=\"hljs-string\"\u003e\u0026quot;my_password\u0026quot;\u003c/span\u003e\n\n\u003cspan class=\"hljs-function\"\u003e\u003cspan class=\"hljs-keyword\"\u003edef\u003c/span\u003e \u003cspan class=\"hljs-title\"\u003esend_email\u003c/span\u003e(\u003cspan class=\"hljs-params\"\u003esubject, body, sender, receivers, password\u003c/span\u003e):\u003c/span\u003e\n msg = MIMEText(body)\n\n msg[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Subject\u0026#x27;\u003c/span\u003e] = subject\n msg[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;From\u0026#x27;\u003c/span\u003e] = sender\n msg[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;To\u0026#x27;\u003c/span\u003e] = \u003cspan class=\"hljs-string\"\u003e\u0026#x27;, \u0026#x27;\u003c/span\u003e.join(receivers)\n\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e smtplib.SMTP_SSL(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.gmail.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e465\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e smtp_server:\n smtp_server.login(sender, password)\n smtp_server.sendmail(sender, receivers, msg.as_string()) \n\n \u003cspan class=\"hljs-built_in\"\u003eprint\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026quot;The plain text email is sent successfully!\u0026quot;\u003c/span\u003e)\n\nsend_email(subject, body, sender, receivers, password)\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003esender\u003c/code\u003e: This contains the sender's address.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ereceivers\u003c/code\u003e: This contains email addresses of receiver 1 and receiver 2.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003emsg\u003c/code\u003e: This is the content of the email.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003esendmail()\u003c/code\u003e: This is the SMTP object's instance method. It takes three parameters - sender, receiver, and msg and sends the message.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ewith\u003c/code\u003e: This is a context manager that is used to properly close an SMTP connection once an email is sent.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eMIMEText\u003c/code\u003e: This holds only plain text.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"2sendinganemailwithattachments\"\u003e2. Sending an Email with Attachments\u003c/h2\u003e\n\u003cp\u003eTo send an email in Python with attachments securely, you will need some additional libraries like MIMEBase and encoders. Here's the code for this case:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e encoders\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.base \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEBase\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.multipart \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEMultipart\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.text \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEText\n\nsender = \u003cspan class=\"hljs-string\"\u003e\u0026quot;sender1@gmail.com\u0026quot;\u003c/span\u003e\npassword = \u003cspan class=\"hljs-string\"\u003e\u0026quot;my_password\u0026quot;\u003c/span\u003e\nreceiver = \u003cspan class=\"hljs-string\"\u003e\u0026quot;receiver1@gmail.com\u0026quot;\u003c/span\u003e\nsubject = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Email with Attachments\u0026quot;\u003c/span\u003e\nbody = \u003cspan class=\"hljs-string\"\u003e\u0026quot;This is an email with attachments created in Python using Gmail SMTP and SSL.\u0026quot;\u003c/span\u003e\n\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e \u003cspan class=\"hljs-built_in\"\u003eopen\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026quot;attachment.txt\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026quot;rb\u0026quot;\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e attachment:\n part = MIMEBase(\u003cspan class=\"hljs-string\"\u003e\u0026quot;application\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026quot;octet-stream\u0026quot;\u003c/span\u003e) \u003cspan class=\"hljs-comment\"\u003e# Adding the attachment to the email\u003c/span\u003e\n part.set_payload(attachment.read())\n \nencoders.encode_base64(part)\npart.add_header(\n \u003cspan class=\"hljs-string\"\u003e\u0026quot;Content-Disposition\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-comment\"\u003e# The header indicates that the file name is an attachment. \u003c/span\u003e\n \u003cspan class=\"hljs-string\"\u003ef\u0026quot;attachment; filename=\u0026#x27;attachment.txt\u0026#x27;\u0026quot;\u003c/span\u003e,\n)\n\nmessage = MIMEMultipart()\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Subject\u0026#x27;\u003c/span\u003e] = subject\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;From\u0026#x27;\u003c/span\u003e] = sender\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;To\u0026#x27;\u003c/span\u003e] = receiver\nhtml_part = MIMEText(body)\nmessage.attach(html_part) \u003cspan class=\"hljs-comment\"\u003e# To attach the file\u003c/span\u003e\nmessage.attach(part)\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e smtplib.SMTP_SSL(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.gmail.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e465\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e server:\n server.login(sender, password)\n server.sendmail(sender, receiver, message.as_string())\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003eMIMEMultipart\u003c/code\u003e: This library allows you to add text and attachments both to an email separately.\u003c/li\u003e\n\u003cli\u003e'rb': It represents binary mode for the attachment to be opened and the content to be read.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eMIMEBase\u003c/code\u003e: This object is applicable to any file type.\u003c/li\u003e\n\u003cli\u003eEncode and Base64: The file will be encoded in \u003ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://stackabuse.com/encoding-and-decoding-base64-strings-in-python/\"\u003eBase64\u003c/a\u003e for safe email sending.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"sendinganhtmlemailinpython\"\u003eSending an HTML Email in Python\u003c/h3\u003e\n\u003cp\u003eTo send an HTML email in Python using Gmail SMTP, you need a class - MIMEText.\u003c/p\u003e\n\u003cp\u003eHere's the full code for \u003ca href=\"https://mailtrap.io/blog/python-send-html-email/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003ePython send HTML email\u003c/a\u003e:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.text \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEText\n\nsender = \u003cspan class=\"hljs-string\"\u003e\u0026quot;sender1@gmail.com\u0026quot;\u003c/span\u003e\npassword = \u003cspan class=\"hljs-string\"\u003e\u0026quot;my_password\u0026quot;\u003c/span\u003e\n\nreceiver = \u003cspan class=\"hljs-string\"\u003e\u0026quot;receiver1@gmail.com\u0026quot;\u003c/span\u003e\nsubject = \u003cspan class=\"hljs-string\"\u003e\u0026quot;HTML Email in Python\u0026quot;\u003c/span\u003e\n\nbody = \u003cspan class=\"hljs-string\"\u003e\u0026quot;\u0026quot;\u0026quot;\n\u0026lt;html\u0026gt;\n \u0026lt;body\u0026gt;\n \u0026lt;p\u0026gt;HTML email created in Python with SSL and Gmail SMTP.\u0026lt;/p\u0026gt;\n \u0026lt;/body\u0026gt;\n\u0026lt;/html\u0026gt;\n\u0026quot;\u0026quot;\u0026quot;\u003c/span\u003e\n\nmessage = MIMEText(body, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;html\u0026#x27;\u003c/span\u003e) \u003cspan class=\"hljs-comment\"\u003e# To attach the HTML content to the email\u003c/span\u003e\n\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Subject\u0026#x27;\u003c/span\u003e] = subject\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;From\u0026#x27;\u003c/span\u003e] = sender\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;To\u0026#x27;\u003c/span\u003e] = receiver\n\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e smtplib.SMTP_SSL(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.gmail.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e465\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e server:\n server.login(sender, password)\n server.sendmail(sender, receiver, message.as_string())\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch2 id=\"testingyouremailwithauthenticationandencryption\"\u003eTesting Your Email With Authentication and Encryption\u003c/h2\u003e\n\u003cp\u003eTesting your emails before sending them to the recipients is important. It enables you to discover any issues or bugs in sending emails or with the formatting, content, etc.\u003c/p\u003e\n\u003cp\u003eThus, always test your emails on a staging server before delivering them to your target recipients, especially when sending emails in bulk. Testing emails provide the following advantages:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eEnsures the email sending functionality is working fine\u003c/li\u003e\n\u003cli\u003eEmails have proper formatting and no broken links or attachments\u003c/li\u003e\n\u003cli\u003ePrevents flooding the recipient's inbox with a large number of test emails\u003c/li\u003e\n\u003cli\u003eEnhances email deliverability and reduces spam rates\u003c/li\u003e\n\u003cli\u003eEnsures the email and its contents stay protected from attacks and unauthorized access\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eTo test this combined setup of sending emails in Python with authentication and encryption enabled, use an email testing server like Mailtrap Email Testing. This will capture all the SMTP traffic from the staging environment, and detect and debug your emails before sending them. It will also analyze the email content, validate CSS/HTML, and provide a spam score so you can improve your email sending.\u003c/p\u003e\n\u003cp\u003eTo get started:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eOpen \u003ca href=\"https://mailtrap.io/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eMailtrap Email Testing\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eGo to 'My Inbox'\u003c/li\u003e\n\u003cli\u003eClick on 'Show Credentials' to get your test credentials - login and password details\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003e\u003cstrong\u003eHere's the Full Code Example for Testing Your Emails:\u003c/strong\u003e\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e socket \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e gaierror\n\nport = \u003cspan class=\"hljs-number\"\u003e2525\u003c/span\u003e \u003cspan class=\"hljs-comment\"\u003e# Define the SMTP server separately\u003c/span\u003e\nsmtp_server = \u003cspan class=\"hljs-string\"\u003e\u0026quot;sandbox.smtp.mailtrap.io\u0026quot;\u003c/span\u003e\nlogin = \u003cspan class=\"hljs-string\"\u003e\u0026quot;xyz123\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-comment\"\u003e# Paste your Mailtrap login details\u003c/span\u003e\npassword = \u003cspan class=\"hljs-string\"\u003e\u0026quot;abc$$\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-comment\"\u003e# Paste your Mailtrap password\u003c/span\u003e\nsender = \u003cspan class=\"hljs-string\"\u003e\u0026quot;test_sender@test.com\u0026quot;\u003c/span\u003e\nreceiver = \u003cspan class=\"hljs-string\"\u003e\u0026quot;test_receiver@example.com\u0026quot;\u003c/span\u003e\n\nmessage = \u003cspan class=\"hljs-string\"\u003ef\u0026quot;\u0026quot;\u0026quot;\\\nSubject: Hello There!\nTo: \u003cspan class=\"hljs-subst\"\u003e{receiver}\u003c/span\u003e\nFrom: \u003cspan class=\"hljs-subst\"\u003e{sender}\u003c/span\u003e\nThis is a test email.\u0026quot;\u0026quot;\u0026quot;\u003c/span\u003e\n\n\u003cspan class=\"hljs-keyword\"\u003etry\u003c/span\u003e:\n \u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e smtplib.SMTP(smtp_server, port) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e server: \u003cspan class=\"hljs-comment\"\u003e# Use Mailtrap-generated credentials for port, server name, login, and password\u003c/span\u003e\n server.login(login, password)\n server.sendmail(sender, receiver, message)\n \u003cspan class=\"hljs-built_in\"\u003eprint\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Sent\u0026#x27;\u003c/span\u003e)\n\n\u003cspan class=\"hljs-keyword\"\u003eexcept\u003c/span\u003e (gaierror, ConnectionRefusedError): \u003cspan class=\"hljs-comment\"\u003e# In case of errors\u003c/span\u003e\n \u003cspan class=\"hljs-built_in\"\u003eprint\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Unable to connect to the server.\u0026#x27;\u003c/span\u003e)\n\n\u003cspan class=\"hljs-keyword\"\u003eexcept\u003c/span\u003e smtplib.SMTPServerDisconnected:\n \u003cspan class=\"hljs-built_in\"\u003eprint\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Server connection failed!\u0026#x27;\u003c/span\u003e)\n\n\u003cspan class=\"hljs-keyword\"\u003eexcept\u003c/span\u003e smtplib.SMTPException \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e e:\n \u003cspan class=\"hljs-built_in\"\u003eprint\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;SMTP error: \u0026#x27;\u003c/span\u003e + \u003cspan class=\"hljs-built_in\"\u003estr\u003c/span\u003e(e))\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eIf there's no error, you should see this message in the receiver's inbox:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003eThis is a test email.\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch2 id=\"bestpracticesforsecureemailsending\"\u003eBest Practices for Secure Email Sending\u003c/h2\u003e\n\u003cp\u003eConsider the below \u003cstrong\u003ePython email best practices\u003c/strong\u003e for secure email sending:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eProtect data\u003c/strong\u003e: Take appropriate security measures to protect your sensitive data such as SMTP credentials, API keys, etc. Store them in a secure, private place like config files or environment variables, ensuring no one can access them publicly.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eEncryption and authentication\u003c/strong\u003e: Always use email encryption and authentication so that only authorized individuals can access your emails and their content.\u003c/p\u003e\n\u003cp\u003eFor authentication, you can use advanced methods like API keys, two-factor authentication, single sign-on (SSO), etc. Similarly, use advanced encryption techniques like SSL, TLS, E2EE, etc.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eError handling\u003c/strong\u003e: Manage network issues, authentication errors, and other issues by handling errors effectively using \u003ccode\u003eexcept/try\u003c/code\u003e blocks in your code.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eRate-Limiting\u003c/strong\u003e: Maintain high email deliverability by rate-limiting the email sending functionality to prevent exceeding your service limits.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eValidate Emails\u003c/strong\u003e: \u003ca href=\"https://stackabuse.com/validate-email-addresses-in-python-with-email-validator/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eValidate email addresses\u003c/a\u003e from your list and remove invalid ones to enhance email deliverability and prevent your domain from getting marked as spam. You can use an \u003ca href=\"https://stackabuse.com/python-validate-email-address-with-regular-expressions-regex/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eemail validation tool\u003c/a\u003e to do this.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eEducate\u003c/strong\u003e: Keep your team updated with secure email practices and cybersecurity risks. Monitor your spam score and email deliverability rates, and work to improve them.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"wrappingup\"\u003eWrapping Up\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003eSecure email sending with Python\u003c/strong\u003e using advanced email encryption methods like SSL, TLS, and end-to-end encryption, as well as authentication protocols and techniques such as SPF, DMARC, 2FA, and API keys.\u003c/p\u003e\n\u003cp\u003eBy combining these security measures, you can protect your confidential email information, improve email deliverability, and maintain trust with your target recipients. In this way, only individuals with appropriate credentials can access it. This will help prevent unauthorized access, data breaches, and other cybersecurity attacks.\u003c/p\u003e\n","parent_id":null,"type":"article","visibility":"public","img_feature":null,"is_featured":false,"locale":"en","custom_excerpt":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"comment_id":null,"og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"read_time_min":19,"published_at":1726712953211,"created_at":1726711039615,"updated_at":1726712957181,"contributors":[{"id":1,"name":"Scott Robinson","slug":"scott","role_id":1,"img_profile":"//s3.stackabuse.com/media/users/1922fc67b9d11d6364dc01a3d19f4293.jpg","img_cover":null,"bio_html":"","website":null,"location":"Omaha, NE","facebook":null,"twitter":"ScottWRobinson","github":"scottwrobinson","created_at":1431311293000,"updated_at":1676411663329,"role":"owner","_pivot_content_id":2134,"_pivot_user_id":1,"_pivot_role":"editor","_pivot_sort_order":1},{"id":26126,"name":"Ivan Djuric","slug":"ivan","role_id":null,"img_profile":"https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg","img_cover":null,"bio_html":"\u003cp\u003eI鈥檓 a Technical Content Writer with 5 years of background covering email-related topics in tight collaboration with software engineers and email marketers. I just love to research and share actionable insights with you about email sending, testing, deliverability improvements, and more. Happy to be your guide in the world of emails!\u003c/p\u003e\n","website":null,"location":null,"facebook":null,"twitter":null,"github":null,"created_at":1724257087195,"updated_at":1724257803744,"role":"contributor","_pivot_content_id":2134,"_pivot_user_id":26126,"_pivot_role":"author","_pivot_sort_order":0}],"tags":[{"id":9,"name":"python","slug":"python","img_cover":null,"description_html":"","og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"color":null,"created_at":1431358631000,"updated_at":1431358631000,"_pivot_content_id":2134,"_pivot_tag_id":9,"_pivot_sort_order":0},{"id":108,"name":"email","slug":"email","img_cover":null,"description_html":"","og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"color":null,"created_at":1538359651000,"updated_at":1538359651000,"_pivot_content_id":2134,"_pivot_tag_id":108,"_pivot_sort_order":1}],"_pivot_user_id":26126,"_pivot_content_id":2134},{"id":2132,"title":"Building Custom Email Templates with HTML and CSS in Python","slug":"building-custom-email-templates-with-html-and-css-in-python","body_html":"\u003cp\u003eAn HTML email utilizes HTML code for presentation. Its design is heavy and looks like a modern web page, rich with visual elements like images, videos, etc., to emphasize different parts of an email's content.\u003c/p\u003e\n\u003cp\u003eBuilding email templates tailored to your brand is useful for various email marketing purposes such as welcoming new customers, order confirmation, and so on. Email template customization allows you to save time by not having to create emails from scratch each time. You can also include an \u003ca href=\"https://mailtrap.io/blog/mailto-links-explained/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eemail link in HTML\u003c/a\u003e to automatically compose emails in your email client.\u003c/p\u003e\n\u003cp\u003eIn this step-by-step guide, you'll learn how to build an HTML email template, add a CSS email design to it, and send it to your target audience.\u003c/p\u003e\n\u003ch2 id=\"settingupyourtemplatedirectoryandjinja2\"\u003eSetting Up Your Template Directory and Jinja2\u003c/h2\u003e\n\u003cp\u003eFollow the steps below to set up your HTML email template directory and Jinja2 for Python email automation:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eCreate a Template Directory\u003c/strong\u003e: To hold your HTML email templates, you will need to set up a template directory inside your project module. Let's name this directory - \u003ccode\u003ehtml_emailtemp\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInstall Jinja2\u003c/strong\u003e: Jinja is a popular templating engine for Python that developers use to create configuration files, HTML documents, etc. Jinja2 is its latest version. It lets you create dynamic content via loops, blocks, variables, etc. It's used in various Python projects, like building websites and microservices, automating emails with Python, and more.\u003c/p\u003e\n\u003cp\u003eUse this command to install Jinja2 on your computer:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003epip install jinja2\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"creatinganhtmlemailtemplate\"\u003eCreating an HTML Email Template\u003c/h2\u003e\n\u003cp\u003eTo create an \u003ca href=\"https://mailtrap.io/blog/html-email/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eHTML email\u003c/a\u003e template, let's understand how to code your email step by step. If you want to modify your templates, you can do it easily by following the steps below:\u003c/p\u003e\n\u003ch3 id=\"step1structurehtml\"\u003eStep 1: Structure HTML\u003c/h3\u003e\n\u003cp\u003eA basic email will have a proper structure - a header, a body, and a footer.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eHeader\u003c/strong\u003e: Used for branding purposes (in emails, at least)\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eBody\u003c/strong\u003e: It will house the main text or content of the email\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eFooter\u003c/strong\u003e: It's at the end of the email if you want to add more links, information, or call-to-actions (CTA)\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eBegin by creating your HTML structure, keeping it simple since email clients are less compatible than web browsers. For example, using tables is preferable for custom email layouts.\u003c/p\u003e\n\u003cp\u003eHere's how you can create a basic HTML mail with a defined structure:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-meta\"\u003e\u0026lt;!DOCTYPE \u003cspan class=\"hljs-meta-keyword\"\u003ehtml\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ehtml\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003elang\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;en\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ehead\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003emeta\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003echarset\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;UTF-8\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003emeta\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ename\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;viewport\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003econtent\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;width=device-width, initial-scale=1\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etitle\u003c/span\u003e\u0026gt;\u003c/span\u003eHTML Email Template\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etitle\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003etype\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;text/css\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\u003cspan class=\"css\"\u003e\n \u003cspan class=\"hljs-comment\"\u003e/* Add your CSS here */\u003c/span\u003e\n \u003c/span\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ehead\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ebody\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;100%\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;600\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Header --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;background-color: #1c3f60; color: #ffffff; text-align: center; padding: 20px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003eYour order is confirmed\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Body --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;padding: 20px; font-size: 16px; line-height: 1.6; color:#ffffff;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003eThe estimated delivery date is 22nd August 2024.\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Footer --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;background-color: #ff6100; color: #000000; text-align: center; padding: 20px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003eFor additional help, contact us at support@domain.com\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ebody\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ehtml\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;!DOCTYPE html\u0026gt;\u003c/code\u003e: This declares HTML as your document type.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;html\u0026gt;\u003c/code\u003e: This is an HTML page's root element.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;head\u0026gt;\u003c/code\u003e: This stores the document's metadata, like CSS styles.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;style\u0026gt;\u003c/code\u003e: CSS styles are defined here.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;body\u0026gt;\u003c/code\u003e: This stores your email's main content.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;table\u0026gt;\u003c/code\u003e: This tag defines the email layout, giving it a tabular structure with cells and rows, which makes rendering easier for email clients.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;tr\u0026gt;\u003c/code\u003e: This tag defines the table's row, allowing vertical content stacking.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;td\u0026gt;\u003c/code\u003e: This tag is used to define a cell inside a row. It contains content like images, text, buttons, etc.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"step2structureyouremail\"\u003eStep 2: Structure Your Email\u003c/h3\u003e\n\u003cp\u003eNow, let's create the structure of your HTML email. To ensure it's compatible with different email clients, use tables to generate a custom email layout, instead of CSS.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;100%\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;600\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;border: 1px solid #1c3f60; padding: 20px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;color: #7ed957;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eHi, Jon!\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;font-size: 16px; color: #ffde59;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eThank you for being our valuable customer!\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch2 id=\"stylingtheemailwithcss\"\u003eStyling the Email with CSS\u003c/h2\u003e\n\u003cp\u003eOnce you've defined your email structure, let's start designing emails with HTML and CSS:\u003c/p\u003e\n\u003ch3 id=\"inlinecss\"\u003eInline CSS\u003c/h3\u003e\n\u003cp\u003eUse inline CSS to ensure different email clients render CSS accurately and preserve the intended aesthetics of your email style.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;font-size: 16px; color: blue;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eStyled paragraph.\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch3 id=\"adjustingstyle\"\u003eAdjusting Style\u003c/h3\u003e\n\u003cp\u003eUsers might use different devices and screen sizes to view your email. Therefore, it's necessary to adapt the style to suit various screen sizes. In this case, we'll use media queries to achieve this goal and facilitate responsive email design.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003etype\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;text/css\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\u003cspan class=\"css\"\u003e\n \u003cspan class=\"hljs-keyword\"\u003e@media\u003c/span\u003e screen \u003cspan class=\"hljs-keyword\"\u003eand\u003c/span\u003e (\u003cspan class=\"hljs-attribute\"\u003emax-width\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e600px\u003c/span\u003e) {\n \u003cspan class=\"hljs-selector-class\"\u003e.container\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ewidth\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e100%\u003c/span\u003e \u003cspan class=\"hljs-meta\"\u003e!important\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e10px\u003c/span\u003e \u003cspan class=\"hljs-meta\"\u003e!important\u003c/span\u003e;\n }\n }\n\u003c/span\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003eclass\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;container\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;600\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Content --\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003e@media screen and (max-width: 600px) {....}\u003c/code\u003e: This is a media query that targets device screens of up to 600 pixels, ensuring the style applies only to these devices, such as tablets and smartphones.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ewidth: 100% !important;\u003c/code\u003e: This style changes the width of the table - .container. The code instructs that the table width be set to full screen, not 600px.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e!important\u003c/code\u003e: This rule overrides other styles that may conflict with it.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003epadding: 10px !important;\u003c/code\u003e: Inside the .container table, a padding of 10px is added to the table.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"addingctabuttonandlinks\"\u003eAdding CTA Button and Links\u003c/h3\u003e\n\u003cp\u003eHere, we are adding a call to action (CTA) link at the button - \u0026quot;Get a 30-day free trial\u0026quot; that points to this page - \u003ccode\u003ehttps://www.mydomain.com\u003c/code\u003e.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;margin: auto;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;background-color: #8c52ff; padding: 10px 20px; border-radius: 5px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ea\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ehref\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;https://www.mydomain.com\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003etarget\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;_blank\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;color: #ffffff; text-decoration: none; font-weight: bold;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eGet a 30-day free trial\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ea\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eLet's Now Look at the Complete HTML Email Template:\u003c/strong\u003e\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-meta\"\u003e\u0026lt;!DOCTYPE \u003cspan class=\"hljs-meta-keyword\"\u003ehtml\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ehtml\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003elang\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;en\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ehead\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003emeta\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003echarset\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;UTF-8\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003emeta\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ename\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;viewport\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003econtent\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;width=device-width, initial-scale=1\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etitle\u003c/span\u003e\u0026gt;\u003c/span\u003eHTML Email Template\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etitle\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003etype\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;text/css\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\u003cspan class=\"css\"\u003e\n \u003cspan class=\"hljs-comment\"\u003e/* Adding the CSS */\u003c/span\u003e\n \n \u003cspan class=\"hljs-selector-tag\"\u003ebody\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003emargin\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e0\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e0\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#f4f4f4\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003efont-family\u003c/span\u003e: Arial, sans-serif;\n }\n \n \u003cspan class=\"hljs-selector-tag\"\u003etable\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003eborder-collapse\u003c/span\u003e: collapse;\n }\n \n \u003cspan class=\"hljs-selector-class\"\u003e.mailcontainer\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ewidth\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e100%\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003emax-width\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e600px\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003emargin\u003c/span\u003e: auto;\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#ffffff\u003c/span\u003e;\n }\n \n \u003cspan class=\"hljs-selector-class\"\u003e.header\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#1c3f60\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ecolor\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#ffffff\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003etext-align\u003c/span\u003e: center;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e20px\u003c/span\u003e;\n }\n \n \u003cspan class=\"hljs-selector-class\"\u003e.body\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e20px\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003efont-size\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e16px\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003eline-height\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e1.6\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#1c3f60\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ecolor\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#7ed957\u003c/span\u003e;\n }\n \n \u003cspan class=\"hljs-selector-class\"\u003e.footer\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#ff6100\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ecolor\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#000000\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003etext-align\u003c/span\u003e: center;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e20px\u003c/span\u003e;\n }\n \n \u003cspan class=\"hljs-selector-class\"\u003e.cta\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ebackground-color\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#8c52ff\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e10px\u003c/span\u003e \u003cspan class=\"hljs-number\"\u003e20px\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003eborder-radius\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e5px\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003ecolor\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e#ffffff\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003etext-decoration\u003c/span\u003e: none;\n \u003cspan class=\"hljs-attribute\"\u003efont-weight\u003c/span\u003e: bold;\n }\n \n \u003cspan class=\"hljs-keyword\"\u003e@media\u003c/span\u003e screen \u003cspan class=\"hljs-keyword\"\u003eand\u003c/span\u003e (\u003cspan class=\"hljs-attribute\"\u003emax-width\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e600px\u003c/span\u003e) {\n \u003cspan class=\"hljs-selector-class\"\u003e.container\u003c/span\u003e {\n \u003cspan class=\"hljs-attribute\"\u003ewidth\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e100%\u003c/span\u003e \u003cspan class=\"hljs-meta\"\u003e!important\u003c/span\u003e;\n \u003cspan class=\"hljs-attribute\"\u003epadding\u003c/span\u003e: \u003cspan class=\"hljs-number\"\u003e10px\u003c/span\u003e \u003cspan class=\"hljs-meta\"\u003e!important\u003c/span\u003e;\n }\n }\n \u003c/span\u003e\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003estyle\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ehead\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ebody\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;100%\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003eclass\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;container\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;600\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Header --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003eclass\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;header\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003eYour order is confirmed\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Body --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003eclass\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;body\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003eThe estimated delivery date is 22nd August 2024.\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;font-size: 16px; color: blue;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eStyled paragraph.\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ewidth\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;100%\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;border: 1px solid #1c3f60; padding: 20px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;color: #7ed957;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eHi, Jon!\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003eh1\u003c/span\u003e\u0026gt;\u003c/span\u003e \n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;font-size: 16px; color: #ffde59;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eThank you for being our valuable customer!\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellpadding\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ecellspacing\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;0\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;margin: auto;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ealign\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;center\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;background-color: #8c52ff; padding: 10px 20px; border-radius: 5px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ea\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003ehref\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;https://www.mydomain.com\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003etarget\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;_blank\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003erel\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;noopener noreferrer\u0026quot;\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;color: #ffffff; text-decoration: none; font-weight: bold;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003eGet a 30-day free trial\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ea\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-comment\"\u003e\u0026lt;!-- Footer --\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e \u003cspan class=\"hljs-attr\"\u003estyle\u003c/span\u003e=\u003cspan class=\"hljs-string\"\u003e\u0026quot;background-color: #ff6100; color: #000000; text-align: center; padding: 20px;\u0026quot;\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003eFor additional help, contact us at support@domain.com\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ep\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etd\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etr\u003c/span\u003e\u0026gt;\u003c/span\u003e\n \u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003etable\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ebody\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\n\u003cspan class=\"hljs-tag\"\u003e\u0026lt;/\u003cspan class=\"hljs-name\"\u003ehtml\u003c/span\u003e\u0026gt;\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003e.mailcontainer\u003c/code\u003e: This is a class that you can use to style your email content's main section. It's given a set width, margin, border, and color.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e.header\u003c/code\u003e, \u003ccode\u003e.footer\u003c/code\u003e, \u003ccode\u003e.body\u003c/code\u003e: These are classes used to style your email's header, footer, and body, respectively.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e.cta\u003c/code\u003e: This class allows you to style your buttons, such as CTA buttons, with a specified color, border design, padding, etc.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"bringingeverythingtogetherwithjinja2\"\u003eBringing Everything Together With Jinja2\u003c/h2\u003e\n\u003cp\u003eHaving created our HTML template, it's now time to bring everything together using the Jinja2 templating engine.\u003c/p\u003e\n\u003ch3 id=\"importprojectmodules\"\u003eImport Project Modules\u003c/h3\u003e\n\u003cp\u003eYou've already set up your template directory - \u003ccode\u003ehtml_emailtemp\u003c/code\u003e. Now you can find and render templates using code. But before you do that, import the relevant project modules using the code below:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e jinja2 \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e Environment, PackageLoader, select_autoescape\n\nenv = Environment(loader=PackageLoader(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;email_project\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;html_emailtemp\u0026#x27;\u003c/span\u003e), autoescape=select_autoescape([\u003cspan class=\"hljs-string\"\u003e\u0026#x27;html\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;xml\u0026#x27;\u003c/span\u003e]))\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eEnvironment: Jinja2 utilizes a central object, the template Environment. Its instances store global objects and configurations, and load your email templates from a file.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003ePackageLoader\u003c/code\u003e: This configures Jinja2 to load email templates.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003eautoescape\u003c/code\u003e: To mitigate security threats such as cross-site scripting (XSS) attacks and protect your code, you can escape values (that are passed to the email template) while rendering HTML using the command \u003ccode\u003eautoescape\u003c/code\u003e. Or, you can validate user inputs to reject malicious code.\u003c/p\u003e\n\u003cp\u003eFor security, \u003ccode\u003eautoescape\u003c/code\u003e is set to \u003ccode\u003eTrue\u003c/code\u003e to enable escaping values. If you turn it to \u003ccode\u003eFalse\u003c/code\u003e, Jinja2 won't be able to escape values, and XSS attacks may occur. To enable autoescape, set \u003ccode\u003eautoescape\u003c/code\u003e to \u003ccode\u003eTrue\u003c/code\u003e:\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eenv = Environment(loader=PackageLoader(\u0026quot;myapp\u0026quot;), autoescape=True)\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"loadyourtemplate\"\u003eLoad Your Template\u003c/h3\u003e\n\u003cp\u003eOnce done, a template environment will be created with a template loader to find email templates created inside your project module's template folder.\u003c/p\u003e\n\u003cp\u003eNext, load your HTML email template using the method - \u003ccode\u003eget_template()\u003c/code\u003e. This function will return your loaded template. It also offers several benefits such as enabling email template inheritance, so you can reuse the template in multiple scenarios.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003etemplate1 = env.get_template(\u0026quot;myemailtemplate.html\u0026quot;)\u003c/code\u003e\u003c/p\u003e\n\u003ch3 id=\"renderthetemplate\"\u003eRender the Template\u003c/h3\u003e\n\u003cp\u003eTo render your email template, use the method - \u003ccode\u003erender()\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003ehtml1 = template1.render()\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eAs these HTML email templates are dynamic, you can pass keyworded arguments (kwargs) with Jinja2 to the \u003ccode\u003erender\u003c/code\u003e function. The kwargs will then be passed to your email template. Here's how you can render your templates using the destined user's name - \u0026quot;Jon Doe\u0026quot; - in your email.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003ehtml1 = template1.render(name=\u0026quot;Jon Doe\u0026quot;)\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eLet's look at the complete code for this section:\u003c/strong\u003e\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e jinja2 \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e Environment, PackageLoader, select_autoescape\n\nenv = Environment(loader=PackageLoader(\u003cspan class=\"hljs-string\"\u003e\u0026quot;email_project\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026quot;html_emailtemp\u0026quot;\u003c/span\u003e),\n autoescape=select_autoescape([\u003cspan class=\"hljs-string\"\u003e\u0026quot;html\u0026quot;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026quot;xml\u0026quot;\u003c/span\u003e]))\n\ntemplate1 = env.get_template(\u003cspan class=\"hljs-string\"\u003e\u0026quot;myemailtemplate.html\u0026quot;\u003c/span\u003e)\nhtml1 = template1.render()\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch2 id=\"sendingtheemail\"\u003eSending the Email\u003c/h2\u003e\n\u003cp\u003eTo send an email, you can use the application-level, straightforward protocol - Simple Mail Transfer Protocol (SMTP). This protocol streamlines the email sending process and determines how to format, send, and encrypt your emails between the source and destination mail servers.\u003c/p\u003e\n\u003cp\u003eIn this instance, we'll send emails in Python via SMTP since Python offers a built-in module for email sending. To send emails, Python provides a library, 'smtplib', to facilitate effortless interaction with the SMTP protocol.\u003c/p\u003e\n\u003cp\u003eTo get started:\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eInstall 'smtplib'\u003c/strong\u003e: Ensure you have installed Python on your system. Now, import 'smtplib' to set up connectivity with the mail server.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eimport smtplib\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eDefine your HTML parameter\u003c/strong\u003e: Define your HTML parameter for the mail object where you'll keep your HTML template. It will instruct email clients to render the template.\u003c/p\u003e\n\u003cp\u003eHere's the full code for this section:\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e smtplib\n\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e email.mime.text \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e MIMEText \u003cspan class=\"hljs-comment\"\u003e# MIMEText is a class from the email package \u003c/span\u003e\n\n\u003cspan class=\"hljs-keyword\"\u003efrom\u003c/span\u003e jinja2 \u003cspan class=\"hljs-keyword\"\u003eimport\u003c/span\u003e Template \u003cspan class=\"hljs-comment\"\u003e# Let\u0026#x27;s use Template class for our HTML template \u003c/span\u003e\n\nsender = \u003cspan class=\"hljs-string\"\u003e\u0026quot;\u0026lt;a href=\u0026#x27;mailto:sender1@gmail.com\u0026#x27; target=\u0026#x27;_blank\u0026#x27; rel=\u0026#x27;noopener noreferrer\u0026#x27;\u0026gt;sender1@gmail.com\u0026lt;/a\u0026gt;\u0026quot;\u003c/span\u003e\n\nrecipient = \u003cspan class=\"hljs-string\"\u003e\u0026quot;\u0026lt;a href=\u0026#x27;mailto:recipient1@gmail.com\u0026#x27; target=\u0026#x27;_blank\u0026#x27; rel=\u0026#x27;noopener noreferrer\u0026#x27;\u0026gt;recipient1@gmail.com\u0026lt;/a\u0026gt;\u0026quot;\u003c/span\u003e\n\nsubject = \u003cspan class=\"hljs-string\"\u003e\u0026quot;Your order is confirmed!\u0026quot;\u003c/span\u003e\n\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e \u003cspan class=\"hljs-built_in\"\u003eopen\u003c/span\u003e(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;myemailtemplate.html\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;r\u0026#x27;\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e f:\n template1 = Template(f.read())\n\n\u003cspan class=\"hljs-comment\"\u003e# Enter the HTML template\u003c/span\u003e\n\nhtml_emailtemp = \u003cspan class=\"hljs-string\"\u003e\u0026quot;\u0026quot;\u0026quot;\n\u0026lt;!DOCTYPE html\u0026gt;\n\u0026lt;html lang=\u0026#x27;en\u0026#x27;\u0026gt;\n\u0026lt;head\u0026gt;\n \u0026lt;meta charset=\u0026#x27;UTF-8\u0026#x27;\u0026gt;\n \u0026lt;meta name=\u0026#x27;viewport\u0026#x27; content=\u0026#x27;width=device-width, initial-scale=1\u0026#x27;\u0026gt;\n\n \u0026lt;title\u0026gt;HTML Email Template\u0026lt;/title\u0026gt;\n\n \u0026lt;style type=\u0026#x27;text/css\u0026#x27;\u0026gt; # Adding the CSS\n body { margin: 0; padding: 0; background-color: #f4f4f4; font-family: Arial, sans-serif; }\n table { border-collapse: collapse; }\n .mailcontainer { width: 100%; max-width: 600px; margin: auto; background-color: #ffffff; }\n .header { background-color: #1c3f60; color: #ffffff; text-align: center; padding: 20px; }\n .body { padding: 20px; font-size: 16px; line-height: 1.6; background-color: #1c3f60; color: #7ed957; }\n .footer { background-color: #ff6100; color: #000000; text-align: center; padding: 20px; }\n .cta { background-color: #8c52ff; padding: 10px 20px; border-radius: 5px; color: #ffffff; text-decoration: none; font-weight: bold; }\n\n @media screen and (max-width: 600px) {\n .container {\n width: 100% !important;\n padding: 10px !important;\n }\n }\n \u0026lt;/style\u0026gt;\n\u0026lt;/head\u0026gt;\n\u0026lt;body\u0026gt;\n \u0026lt;table width=\u0026#x27;100%\u0026#x27; cellpadding=\u0026#x27;0\u0026#x27; cellspacing=\u0026#x27;0\u0026#x27;\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td align=\u0026#x27;center\u0026#x27;\u0026gt;\n \u0026lt;table class=\u0026#x27;container\u0026#x27; width=\u0026#x27;600\u0026#x27; cellpadding=\u0026#x27;0\u0026#x27; cellspacing=\u0026#x27;0\u0026#x27;\u0026gt;\n \u0026lt;!-- Header --\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td class=\u0026#x27;header\u0026#x27;\u0026gt;\n \u0026lt;h1\u0026gt;Your order is confirmed\u0026lt;/h1\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;!-- Body --\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td class=\u0026#x27;body\u0026#x27;\u0026gt;\n \u0026lt;p\u0026gt;The estimated delivery date is 22nd August 2024.\u0026lt;/p\u0026gt;\n \u0026lt;p style=\u0026#x27;font-size: 16px; color: blue;\u0026#x27;\u0026gt;Styled paragraph.\u0026lt;/p\u0026gt;\n \u0026lt;table width=\u0026#x27;100%\u0026#x27; cellpadding=\u0026#x27;0\u0026#x27; cellspacing=\u0026#x27;0\u0026#x27; style=\u0026#x27;border: 1px solid #1c3f60; padding: 20px;\u0026#x27;\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td align=\u0026#x27;center\u0026#x27;\u0026gt;\n \u0026lt;h1 style=\u0026#x27;color: #7ed957;\u0026#x27;\u0026gt;Hi, Jane!\u0026lt;/h1\u0026gt; \n \u0026lt;p style=\u0026#x27;font-size: 16px; color: #ffde59;\u0026#x27;\u0026gt;\n Thank you for being our valuable customer!\n \u0026lt;/p\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;/table\u0026gt;\n \u0026lt;table cellpadding=\u0026#x27;0\u0026#x27; cellspacing=\u0026#x27;0\u0026#x27; style=\u0026#x27;margin: auto;\u0026#x27;\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td align=\u0026#x27;center\u0026#x27; style=\u0026#x27;background-color: #8c52ff; padding: 10px 20px; border-radius: 5px;\u0026#x27;\u0026gt;\n \u0026lt;a href=\u0026#x27;https://www.mydomain.com\u0026#x27; target=\u0026#x27;_blank\u0026#x27; rel=\u0026#x27;noopener noreferrer\u0026#x27; style=\u0026#x27;color: #ffffff; text-decoration: none; font-weight: bold;\u0026#x27;\u0026gt;Get a 30-day free trial\u0026lt;/a\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;/table\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;!-- Footer --\u0026gt;\n \u0026lt;tr\u0026gt;\n \u0026lt;td style=\u0026#x27;background-color: #ff6100; color: #000000; text-align: center; padding: 20px;\u0026#x27;\u0026gt;\n \u0026lt;p\u0026gt;For additional help, contact us at support@domain.com\u0026lt;/p\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;/table\u0026gt;\n \u0026lt;/td\u0026gt;\n \u0026lt;/tr\u0026gt;\n \u0026lt;/table\u0026gt;\n\u0026lt;/body\u0026gt;\n\n\u0026lt;/html\u0026gt;\n\u0026quot;\u0026quot;\u0026quot;\u003c/span\u003e\n\ntemplate1 = Template(html_emailtemp)\nhtml1 = template1.render(name=\u003cspan class=\"hljs-string\"\u003e\u0026quot;Jon Doe\u0026quot;\u003c/span\u003e)\n\n\u003cspan class=\"hljs-comment\"\u003e# Attach your MIMEText objects for HTML\u003c/span\u003e\n\nmessage = MIMEText(html1, \u003cspan class=\"hljs-string\"\u003e\u0026#x27;html\u0026#x27;\u003c/span\u003e)\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;Subject\u0026#x27;\u003c/span\u003e] = subject\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;From\u0026#x27;\u003c/span\u003e] = sender\nmessage[\u003cspan class=\"hljs-string\"\u003e\u0026#x27;To\u0026#x27;\u003c/span\u003e] = recipient\n\n\u003cspan class=\"hljs-comment\"\u003e# Send the HTML email\u003c/span\u003e\n\n\u003cspan class=\"hljs-keyword\"\u003ewith\u003c/span\u003e smtplib.SMTP_SSL(\u003cspan class=\"hljs-string\"\u003e\u0026#x27;smtp.gmail.com\u0026#x27;\u003c/span\u003e, \u003cspan class=\"hljs-number\"\u003e465\u003c/span\u003e) \u003cspan class=\"hljs-keyword\"\u003eas\u003c/span\u003e server:\n server.login(username, password)\n server.sendmail(sender, recipient, message.as_string())\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u003cstrong\u003eExplanation:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003esender\u003c/code\u003e: The sender's email address\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003erecipient\u003c/code\u003e: The recipient's email address\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003efrom email.mime.text import MIMEText\u003c/code\u003e: This is used to import the class MIMEText, enabling you to attach your HTML template in the email.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003esmtplib.SMTP_SSL('smtp.gmail.com', 465) as server:\u003c/code\u003e: This establishes a connection with your email provider's (Gmail's) SMTP server using port 465. If you are using another SMTP provider, use their domain name, such as smtp.domain.com, with an appropriate port number. The connection is secured with SSL.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eserver.login(username, password)\u003c/code\u003e: This function allows you to log in to the email server using your username and password.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eserver.sendemail(sender, recipient, message.as_string())\u003c/code\u003e: This command sends the HTML email.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"testing\"\u003eTesting\u003c/h3\u003e\n\u003cp\u003eBefore sending your HTML email, test it to understand how different email clients render CSS and HTML. Testing tools like Email on Acid, Litmus, etc. can assist you.\u003c/p\u003e\n\u003ch2 id=\"conclusion\"\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eTo build custom email templates with HTML and CSS in Python, follow the above instructions. First, begin structuring your HTML email template, style emails with CSS, and then send them to your recipients. Always check your email template's compatibility with different email clients and ensure to keep your HTML simple using tables. Adding an \u003ca href=\"https://stackabuse.com/python-specific-design-patterns/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003eemail link in HTML\u003c/a\u003e will also allow you to compose an email automatically in your email client and send it to a specific email address.\u003c/p\u003e\n","parent_id":null,"type":"article","visibility":"public","img_feature":null,"is_featured":false,"locale":"en","custom_excerpt":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"comment_id":null,"og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"read_time_min":19,"published_at":1724180684567,"created_at":1724173213441,"updated_at":1724257697915,"contributors":[{"id":1,"name":"Scott Robinson","slug":"scott","role_id":1,"img_profile":"//s3.stackabuse.com/media/users/1922fc67b9d11d6364dc01a3d19f4293.jpg","img_cover":null,"bio_html":"","website":null,"location":"Omaha, NE","facebook":null,"twitter":"ScottWRobinson","github":"scottwrobinson","created_at":1431311293000,"updated_at":1676411663329,"role":"owner","_pivot_content_id":2132,"_pivot_user_id":1,"_pivot_role":"editor","_pivot_sort_order":0},{"id":26126,"name":"Ivan Djuric","slug":"ivan","role_id":null,"img_profile":"https://s3.amazonaws.com/s3.stackabuse.com/media/users/b9227b402289ab251e04427e15e2d4f6.jpg","img_cover":null,"bio_html":"\u003cp\u003eI鈥檓 a Technical Content Writer with 5 years of background covering email-related topics in tight collaboration with software engineers and email marketers. I just love to research and share actionable insights with you about email sending, testing, deliverability improvements, and more. Happy to be your guide in the world of emails!\u003c/p\u003e\n","website":null,"location":null,"facebook":null,"twitter":null,"github":null,"created_at":1724257087195,"updated_at":1724257803744,"role":"contributor","_pivot_content_id":2132,"_pivot_user_id":26126,"_pivot_role":"author","_pivot_sort_order":1}],"tags":[{"id":9,"name":"python","slug":"python","img_cover":null,"description_html":"","og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"color":null,"created_at":1431358631000,"updated_at":1431358631000,"_pivot_content_id":2132,"_pivot_tag_id":9,"_pivot_sort_order":0},{"id":108,"name":"email","slug":"email","img_cover":null,"description_html":"","og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null,"inject_header":null,"inject_footer":null,"canonical_url":null,"color":null,"created_at":1538359651000,"updated_at":1538359651000,"_pivot_content_id":2132,"_pivot_tag_id":108,"_pivot_sort_order":1}],"_pivot_user_id":26126,"_pivot_content_id":2132}],"content_count":"2"},"page":1,"error":null},"__N_SSP":true},"page":"/author/[...slug]","query":{"slug":["ivan"]},"buildId":"1740324887682","isFallback":false,"isExperimentalCompile":false,"gssp":true,"scriptLoader":[]}</script></body></html>