Tech Blog

Coding

Use Mailgun over SMTP

By Vidhathri Avadhany1 min read
← Back to blog

Hello folks!
Mailing is an important part of any application. We will see how we can send emails using SMTP MailGun credentials, without exposing the password of the FromMailer.

Prerequisites

  1. SMTP MailGun Credentials for your organization’s domain

Integrating MailGun over SMTP in C#

Note : The from address should be of the domain for which the MailGun credentials have been purchased

public static void SendMailUsingSmtpMainGun(string mailFrom, string mailTo, string subject, string body, List<string> attachments = null)
{
    var smtpClient = new SmtpClient("smtp.mailgun.org")
    {
        Port = 587,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential("<SmtpUserNameOfMailGun>", "<SmtpPasswordOfMailGun>"]),
        EnableSsl = true,
    };

    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(mailFrom);
    mail.To.Add(mailTo);
    mail.Subject = subject;
    mail.Body = body;

    foreach (string attachment in attachments)
    {
        mail.Attachments.Add(new Attachment(attachment));
    }

    smtpClient.Send(mail);
}

The main advantage of using MailGun is that the sender id’s password isn’t exposed. The ‘From’ address could be any address from the organization domain for which MailGun credentials have been purchased.
Use this and enjoy mailing!!

Keep reading

You may be interested in

Browse all articles →
Active Directory Federation Service
July 5, 20235 min read

Active Directory Federation Service

Active Directory Federation Service (ADFS) uses claims-based identity model to maintain application security and to implement federated identity. ADFS is a concept of Windows Server operating system, that provides users with single sign-on access to the application, those are located across organizational boundaries. For Example: We have 2 organizations – Organization 1 and Organization 2. […]

By Abinash MishraRead More →
Remote Access to Microsoft SQL Database Server
April 5, 20232 min read

Remote Access to Microsoft SQL Database Server

Remote access to a SQL server is important because it allows users to access the server from anywhere, at any time. This enables remote workers to access the data they need when they need it, even if they are not physically in the same location as the server. It also allows IT admins to access […]

By Malkeet SinghRead More →
Types of Load Balancer in AWS
February 6, 20235 min read

Types of Load Balancer in AWS

What is Load Balancing ? Load balancing is a critical component of any scalable and highly available Cloud or On-premise architecture. It helps distribute incoming traffic across multiple servers, improving the availability and scalability of a website or application. In the cloud, load balancing is offered as a service by various cloud providers such as […]

By Keerthik ShenoyRead More →