Hi ,
I have to send mail using private server. But i receive " Failure sending mail. " error
My code
private static void SendMail()
{
try
{
string SmtpHost = ConfigurationManager.AppSettings["SmtpHost"].ToString();
string SmtpFromMail = ConfigurationManager.AppSettings["SmtpFromMail"].ToString();
string SmtpFromMailPwd = ConfigurationManager.AppSettings["SmtpFromMailPwd"].ToString();
//foreach (DataRow dr in objDataTable.Rows)
//{
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress(SmtpFromMail);
//string EventName = DicEventTypeName[dr["Email"].ToString()];
mail.Subject = "Testing";
mail.Body = "Test";
SmtpClient smtp = new SmtpClient();
smtp.Host = SmtpHost; //Or Your SMTP Server Address
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential(SmtpFromMail, SmtpFromMailPwd); //
smtp.EnableSsl = true;
smtp.Send(mail);
}catch(Exception e)
{
}
}
Could you give any suggestion ?
Thanks in advance !!


Sreekanth ReddyRank #726 · 3.2K reputationPosted Nov 12, 2018, 10:22 PM EST
Amit GuptaRank #190 · 12.8K reputationPosted Nov 12, 2018, 10:50 PM EST
Madan ShekarRank #428 · 5.9K reputationPosted Nov 12, 2018, 11:25 PM EST
https://sendgrid.com/docs/for-developers/sending-email/v3-csharp-code-example/
Create account and generate api key start to use
code starts form here , any doubt ping me
// using SendGrid's C# Library// https://github.com/sendgrid/sendgrid-csharpusing SendGrid;using SendGrid.Helpers.Mail;using System;using System.Threading.Tasks;namespace Exampleinternal class Exampleprivate static void Main()static async Task Execute()var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");var client = new SendGridClient(apiKey);var from = new EmailAddress("[email protected]", "Example User");var subject = "Sending with SendGrid is Fun";var to = new EmailAddress("[email protected]", "Example User");var plainTextContent = "and easy to do anywhere, even with C#";var htmlContent = "and easy to do anywhere, even with C#";var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);var response = await client.SendEmailAsync(msg);