This is a simple C# program that send email to recipient. It uses gmail smtp.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace SendEmail
{
class Program
{
static void Main(string[] args)
{
var fromAddress = new MailAddress("from@gmail.com", "From Name");//Email Address for from Email
var toAddress = new MailAddress("to@example.com", "To Name");//Recipient address
const string fromPassword = "fromPassword";//Gmail Password for user
const string subject = "Subject";//Subject of email
const string body = "Body";//Body content for email
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)//Credentials of gmail user
};
using (var message = new MailMessage(fromAddress, toAddress)
{
//IsBodyHtml=true,//Set it to true if your email body contains html content
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
}
}
0 Comment(s)