1

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("test@gmail.com");
message.Subject = "The subject";
message.From = new System.Net.Mail.MailAddress("administrator@sp.spd.local");
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", "test@gmail.com");
headers.Add("From", "administrator@sp.spd.local");
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);
  • Hi medes, can you share your code as well – spStacker Oct 22 '15 at 13:04
2

Most probably the problem does not come from the SharePoint configuration, but from the SMTP relay you use. Do you use IIS 6.0 as the local SMTP? Does it then forward the email to an Exchange server or else? The local SMTP relay or the Exchange server configurations have to be investigated first.

| improve this answer | |
  • thanks Evariste, for now I am using my dev environment which is a single server. If I use System.Net.Mail.SmtpClient with SmtpDeliveryMethod.PickupDirectoryFromIis it sends email to external users also. – Medes Oct 22 '15 at 12:59
  • That probably means your local SMTP relay (IIS 6) rejects SharePoint when it tries to connect it to send to an external user (while droping a file in the pickup folder is OK). So, I'd look at the SMTP config in IIS 6 management console, to check if domains other than local is allowed. – Evariste Oct 22 '15 at 13:24
  • I looked at smtp, every thing looked ok. I am not a smtp guru mybe something I am missing. Which part do I need to configure? – Medes Oct 22 '15 at 15:46
  • Among other things: right-click on "Default SMTP Virtual Server", "Properties", "Access" tab, "Relay..." button, ensure your SharePoint server IP is allowed to relay. Also, in the "Delivery" tab, "Outbound security", check whether the relay you want to use for external connections is correctly set. You need a "real" SMTP server to go out, the one used for your organization. – Evariste Oct 22 '15 at 18:14
  • I did the changes but still it returns false, I think it must be a SharePoint configuration because when I drop an email file to the pickup folder it sends it o my gmail. – Medes Oct 23 '15 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.