Reputation: 251
I am trying to send emails through an MVC App. Everything else seems to be working fine except for smtp.Send(mess)
.
The error description is below:
smtp.ServicePoint.Address threw an exception of type System.NotSupportedException
My code:
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(senderEmail.Address, password)
};
using (var mess = new MailMessage(senderEmail, receiverEmail)
{
Subject = subject,
Body = body
})
{
smtp.Send(mess);
}
What am I doing wrong?
Upvotes: 1
Views: 3444
Reputation: 41
I have checked the web.config file in my project and find out mail is physically strode in the pickupDirectoryLocation="D:\xxxxmaildrop" location and there is no any "xxxxmaildrop" folder in my D drive. So manually created a one. Then run the project. After that step a mail was created in the given location and no exceptions found. Please try this solution too, it worked for me.
<mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory" from="[email protected]"> <specifiedPickupDirectory pickupDirectoryLocation="D:\xxxxmaildrop" /> </smtp> </mailSettings>
Upvotes: 1