<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Durgesh Barwal on Medium]]></title>
        <description><![CDATA[Stories by Durgesh Barwal on Medium]]></description>
        <link>https://medium.com/@durgeshbarwal?source=rss-b67b00d46ae3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sPduRzsWw6tlI1fw.</url>
            <title>Stories by Durgesh Barwal on Medium</title>
            <link>https://medium.com/@durgeshbarwal?source=rss-b67b00d46ae3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:52:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@durgeshbarwal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Send Email with HTML Templates using C#]]></title>
            <link>https://medium.com/@durgeshbarwal/send-email-with-html-templates-using-c-eb97ba9665e5?source=rss-b67b00d46ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb97ba9665e5</guid>
            <category><![CDATA[email]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[smtp]]></category>
            <dc:creator><![CDATA[Durgesh Barwal]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 18:30:06 GMT</pubDate>
            <atom:updated>2020-02-16T18:35:02.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*zu5RtlGpRR0_NcJ94mT4Nw.png" /></figure><p>Hello All,</p><blockquote>This blog consist of the information and code snippets of the complete tutorial for sending emails using C#. Here I captured the necessary information for complete learning for sending emails with attachments, with image source in the body, sending an HTML body, sending emails with Alternative views, basic error that new developer faces during writing code for email.</blockquote><p>First of all, if you have hosting service, than that platform may provide you dedicated hosting services for sending emails.</p><p>If you want to send mail from your code base, without depending on the hosting service then, here is the right information for you.</p><blockquote>You need two object one is the MailMessage (represent the email message that can be send using SmtpClient Class), and second SmtpClient (allow the application to send the email using SMTP Protocol).</blockquote><h4><strong>So, Let first talk about “MailMessage” and it’s different properties which help us to compose our email message.</strong></h4><p>Here is the code snippet: -</p><p><strong>namespaces :</strong>-</p><pre>using System.Net.Mail;<br>using System.Net.Mime;</pre><p><strong>MailMessage Object :-</strong></p><pre>MailMessage mailMessage = new MailMessage();<br>mailMessage.From = new MailAddress(“Senders Email Address”);<br>mailMessage.To.Add(new MailAddress(“Receiver&#39;s Email Address”));<br>mailMessage.Subject = “Subject of the Mail”;</pre><p>We can also add Cc and Bcc recipients email addresses using the below code</p><pre>mailMessage.CC.Add(new MailAddress(“Cc Receiver&#39;s Mail Address”));<br>mailMessage.Bcc.Add(new MailAddress(“Bcc Receiver&#39;s Mail Address”));</pre><p>Here is the code snippet for Email body, We can send the email body as a plain text or with HTML rich content. There is an property “IsBodyHtml”, we need to set true if there is an HTML body, otherwise false.</p><pre>mailMessage.IsBodyHtml = true;<br>mailMessage.Body = &quot;html template as a string for the body&quot;;</pre><p>We can also send <strong>AlternateView </strong>(represent the format to view an Email message) instead of message body. Using AlternativeView, we can also link resource files such as image or any other resource in the HTML body easily. AlternateViews collection to specify <strong>views</strong> with other MIME types.</p><pre>// Reading the Image for the path in MemoryStream <br>MemoryStream ms = new MemoryStream(File.ReadAllBytes(&quot;image_path&quot;));</pre><pre><br>// Create Linked Resource of the memory Stream of the Image<br>// Give the Content Id to the Linked Resource<br>LinkedResource Img = new LinkedResource(ms, MediaTypeNames.Image.Jpeg);<br>Img.ContentId = &quot;MyImage&quot;;</pre><pre><br>// HTML Body with the Content Id of the Linked resource<br>string body = &quot;&lt;img src=cid:MyImage id=\&quot;img\&quot; alt=\&quot;\&quot; width=\&quot;100px\&quot; height=\&quot;100px\&quot; /&gt;&quot;;</pre><pre>//Create AlternateView from the HTML body and add resources object<br>AlternateView alternateView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);<br>alternateView.LinkedResources.Add(Img);</pre><pre>// Attaching the Alternate View to the mailMessage object<br>mailMessage.AlternateViews.Add(alternateView);</pre><p>You can also send the Attachments with the Email using below code:</p><pre>// Attaching the Image File in the Email<br>MemoryStream ms1 = new MemoryStream(File.ReadAllBytes(&quot;file path&quot;));<br>mailMessage.Attachments.Add(new Attachment(ms1, &quot;filename.jpg&quot;));</pre><pre>// Attaching the PDF File in the Email<br>MemoryStream ms2 = new MemoryStream(File.ReadAllBytes(&quot;file_path&quot;));<br>mailMessage.Attachments.Add(new Attachment(ms2, &quot;pdffile.pdf&quot;));</pre><p>This is all about the <strong>MailMessage </strong>object which contain all information of the Email.</p><h4>Now, we have SmtpClient, to send prepared MailMessage . So Let’s start with SmtpClient, which allow sending email using SMTP Protocol.</h4><p>Here, is the code snippet for the SmtpClient Object.</p><pre>SmtpClient sMTPClient = new SmtpClient();<br>sMTPClient.EnableSsl = true;<br>sMTPClient.Host = &quot;smtp.gmail.com&quot;;<br>sMTPClient.Port = 587;<br>sMTPClient.UseDefaultCredentials = false;<br>sMTPClient.Credentials = new System.Net.NetworkCredential(&quot;sender&#39;s email Address&quot;, &quot;password&quot;);<br>sMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;<br>sMTPClient.Send(mailMessage);</pre><blockquote>If you are using your gmail email_Id to send mail using SmtpClient object, your gmail account’s <strong>two</strong>-<strong>factor authentication </strong>should be deactivated. And we also need to disable google’s <strong>Less secure apps </strong>to allow SmtpClient to send mails.</blockquote><p>That’s all. Hope you like you. Clap it. I will get you awesome clapping notifications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb97ba9665e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Captures from the Book : The Power of Now]]></title>
            <link>https://medium.com/@durgeshbarwal/captures-from-the-book-the-power-of-now-9cde9957ca69?source=rss-b67b00d46ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cde9957ca69</guid>
            <category><![CDATA[meditation]]></category>
            <category><![CDATA[reading]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[spirituality]]></category>
            <category><![CDATA[now]]></category>
            <dc:creator><![CDATA[Durgesh Barwal]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 06:05:55 GMT</pubDate>
            <atom:updated>2020-02-16T06:07:34.615Z</atom:updated>
            <content:encoded><![CDATA[<h3>Captures from the Book : The Power of Now</h3><p>Hello All,</p><p>Reading give everyone lot of learning. Yesterday I complete reading of a great book: “Practicing the Power of Now” by Eckhart Tolle. This book leaves an evocative feeling inside me. I will never forget this impact in my life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*K4p3_whnD7qkLOmeatgqjw.jpeg" /></figure><p>This blog contains the clips of that book, which will motivate everyone to stay present. i.e in the state of being and be happy always.</p><p><strong>Here is the list :-</strong></p><ol><li>When your consciousness is directed outwards, mind and world arises. When it is directed inwards, it realizes its own source and returns home into the Unmanifested.</li><li>As long as you are identified with your mind, the ego runs your life.</li><li><strong>Life is Now</strong>.</li><li>The enlightened person’s main focus of attention is always the Now, but still they are peripherally aware of the time. In other words, they continue to use clock time but are free from the psychological time.</li><li>Presence is the key of freedom, so you can only be free now.</li><li><strong>All Problem are illusions of the Mind</strong>.</li><li>Do not be concerned with the fruit of your action — just give attention itself. The fruit will come of its own accord. This is a powerful spiritual practice.</li><li>Love is a state of Being. Your love is not outside; it is deep within you. You can never lose it, and it cannot leave you. It is not dependent on some other body, some external form.</li><li>First you stop judging yourself, then you stop judging your partner. The greatest catalyst for change in a relationship is complete acceptance of your partner as he or she is, without needing to judge or change them in any way.</li><li><strong>Learn to give expression, to what your feel without blaming</strong>. Learn to listen to your partner in an open, non-defensive way.</li><li>In the State of Surrender, you see clearly what need to be done, and you can take actions, doing one thing at a time and focusing on one thing at a time. Learn from nature: see how everything gets accomplished and how the miracle of life unfolds without dissatisfaction or unhappiness. That’s why Jesus said <strong>“Look at the lilies, how they grow; they neither toil nor spin”</strong>.</li></ol><p>That’s all. Hope you like it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cde9957ca69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>