I have an easy way to send emails from a website:
...
using (var mail = new MailMessage(from, sendTo))
{
using (var smtp = new SmtpClient())
{
mail.CC.Add(cc);
mail.Bcc.Add(bcc.Replace(";", ","));
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = html == -1;
mail.Priority = priority;
mail.BodyEncoding = mail.SubjectEncoding = mail.HeadersEncoding = Encoding.UTF8;
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
try
{
if (mail.Body.IsNotEmpty())
{
smtp.Send(mail);
}
}
catch
{
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
if (mail.Body.IsNotEmpty())
{
smtp.Send(mail);
}
}
catch(Exception e)
{
}
}
}
}
Which works great; however, when the sender anything@domainname.comand the recipient bob@domainname.com, emails get stuck in the Dropdirectory folder inetpub/mailrootand are never sent to the recipient.
Question: how can I get around this to send emails to people in the same (local) domain?
source
share