abhishek chauhan

abhishek chauhan

  • NA
  • 127
  • 23.3k

Error: server does not support secure connections.

Feb 27 2017 5:17 AM
After spending , couple of hours i couldn't find solution to this error . I create a application in MVC5 of sending certain fields data to the recipient's mail address after hit the submit button. But when i clicked on it , i got a error i.e. "An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code
Additional information: Server does not support secure connections. "

What I have tried:
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SendEmail.Models;
using System.Net;
using System.Net.Mail;
using System.IO;
namespace SendEmail.Controllers
{
public class GetSendEmailController : Controller
{
// GET: GetSendEmail
// action method handle get operation and simply return view
public ActionResult Index()
{
return View();
}
// action method for handle the call made by the post function from the view
[HttpPost]
public ActionResult Index( EmailModel model)
{
using(var mailmessage = new MailMessage(model.Email,model.To))
{
mailmessage.Body = model.Body;
mailmessage.Subject = model.Subject;
if(model.Attachment.ContentLength > 0)
{
string filename = Path.GetFileName(model.Attachment.FileName);
mailmessage.Attachments.Add(new Attachment(model.Attachment.InputStream, filename));
}
mailmessage.IsBodyHtml = false;
using(var smtpclient = new SmtpClient())
{
smtpclient.Host = "smtp.gmail.com";
smtpclient.EnableSsl = true;
//NetworkCredential networkcredential = new NetworkCredential(model.Email, model.Password);
smtpclient.Credentials = new NetworkCredential(model.Email, model.Password);
smtpclient.UseDefaultCredentials = false;
//smtpclient.Credentials = networkcredential;
smtpclient.Port = 587;
smtpclient.Send(mailmessage); // got error
ViewBag.Message = "Email has been successfully sent...!!! ";
}
}
return View();
}
}
}
 
 
 
Give some hint in which way should i have to proceed to go...!!!
 

Answers (3)