Hot File

How to Email sending in .NET through Gmail

View: 449    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Visual studio & .NET   Fields: Other

8 point/1 review File has been tested

Use System.Net.Mail, not the deprecated System.Web.Mail in C#.

Introduction

Use System.Net.Mail, not the deprecated System.Web.Mail in C#.

Example:

using System.Net;
using System.Net.Mail;
 
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";
 
var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

Important:

Above example will work fine if you change your gmail account setting by visiting https://support.google.com/accounts/answer/6010255?hl=en-GB

Google has recently changed it’s security policy for less secure apps.

How to Email sending in .NET through Gmail

How to Email sending in .NET through Gmail Posted on 22-08-2016  Use System.Net.Mail, not the deprecated System.Web.Mail in C#. 8/10 449

Comment:

To comment you must be logged in members.

Files with category

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd