I have used SPUtility.SendEmail to send email to users programmatically and it works. However if the user's email is different than the outgoing email domain it returns false. How do I make it work for external users as well? It is an on-premise SharePoint 2013 server.
This code works:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("[email protected]");
message.Subject = "The subject";
message.From = new System.Net.Mail.MailAddress("[email protected]");
message.Body = "This is body";
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("sp.spd.local");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Send(message);
This code returns false if you use gmail but returns true if you use same domain email
System.Collections.Specialized.StringDictionary headers = new System.Collections.Specialized.StringDictionary();
headers.Add("To", "[email protected]");
headers.Add("From", "[email protected]");
headers.Add("Subject", "Test Email Subject");
headers.Add("content-type", "text/html");
string bodyText = "This is the body of my email, in html format.";
Boolean sent = SPUtility.SendEmail(currentWeb, headers, bodyText, true);