none
SPutility.SendEmail returns undeliverable email RRS feed

  • Question

  • There's a button in my Sharepoint which executes SPUtility.SendEmail method to an AD group email. However, for users they would receive an undeliverable email as soon as they hit send.

    Delivery has failed to these recipients or groups:
    Your message can't be delivered because delivery to this address is restricted. 

    Diagnostic information for administrators:

    Generating server:
    ......RESOLVER.RST.AuthRequired; authentication required ##

    Monday, October 15, 2012 12:26 AM

Answers

  • You are looking for something like this: SmtpServer.Credentials = new NetworkCredential("user", "password"); 

    instead of: SmtpServer.UseDefaultCredentials = true;


    Patrick Curran | Twitter | Blog
    Click "Mark as Answer" on the post that helps you.
    Click "Unmark as Answer" if a marked post does not actually answer your question.
    Click "Vote As Helpful" if a post has been useful to you.

    Monday, October 15, 2012 4:33 AM
  • You will just pass a valid Domain user account (service account).  Keep in mind this is generally passed to the SMTP server in cleartext, and it isn't advisable to put a cleartext password in code, either.

    SharePoint - Nauplius Applications
    Microsoft SharePoint Server MVP - 2012

    Monday, October 15, 2012 5:43 AM
    Moderator

All replies

  • You may check with your Email Administrators as to whether the SMTP server which is set in the outgoing email settings needs authentication to relay emails.
    Monday, October 15, 2012 1:16 AM
  • Yes, there is an authentication. But users should be able to send email to these groups as they have been doing over Outlook.

    My code in sending email is simply SPUtility.SendEmail(), i thought that would mean to send email within user context?

    I have tried adding run elevated mode as well, still failed...

    Monday, October 15, 2012 1:21 AM
  • Is it safe to assume that you can send normal alert emails out of your farm?  Does email functionality work correctly?  Assuming that farm email is functioning correctly, it sounds like your distribution group might not be set up correctly.  Here is a link on setting up distribution groups: http://technet.microsoft.com/en-us/library/bb125178.aspx  Personally, I have not had much luck with SPutility.SendEmail, and have always used the Smtp.Send method instead.


    Patrick Curran | Twitter | Blog
    Click "Mark as Answer" on the post that helps you.
    Click "Unmark as Answer" if a marked post does not actually answer your question.
    Click "Vote As Helpful" if a post has been useful to you.

    Monday, October 15, 2012 1:30 AM
  • Yes, sending email to regular user works. It's only when it's AD group...

    Oh, I didn't think about using using SMTP Send... will give that a try now.. thanks.

    Monday, October 15, 2012 1:36 AM
  • Your DLs are set to Require authentication.  This is the default for Exchange 2010, and I think 2007 as well.  Since SharePoint is sending mail anonymously, this is why you're getting this error.

    My recommendation would be to not require authentication to send to the DLs.


    SharePoint - Nauplius Applications
    Microsoft SharePoint Server MVP - 2012

    Monday, October 15, 2012 1:59 AM
    Moderator
  • Is there any other way as the network administrator wants to keep the authentication active...

    I tried doing the smtp way, but it's not sending email:

     //send via smtp
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    SmtpClient SmtpServer = new SmtpClient();
    mail.From = new MailAddress(strFromAddress);
    mail.To.Add(toAddress);
    mail.Subject = subject;
    mail.Body = message;
    SmtpServer.Send(mail);



    Monday, October 15, 2012 2:09 AM
  • You can do it one of two ways...

    Install an SMTP server that has anonymous relay access (be it the IIS6 SMTP module or another piece of SMTP software).  Configure that software to send, using a domain account (with user/pass) to Exchange.

    Or, put a domain user/pass in your code and send with SMTP.  Not a very good idea, but it'll work.

    I'd talk to the "network administrator"'s manager :-)


    SharePoint - Nauplius Applications
    Microsoft SharePoint Server MVP - 2012

    Monday, October 15, 2012 2:11 AM
    Moderator
  • If the SMTP host requires credentials, you must set them before calling this method. To specify credentials, use the UseDefaultCredentials or Credentials properties.


    Patrick Curran | Twitter | Blog
    Click "Mark as Answer" on the post that helps you.
    Click "Unmark as Answer" if a marked post does not actually answer your question.
    Click "Vote As Helpful" if a post has been useful to you.

    Monday, October 15, 2012 2:12 AM
  • Hi Guys, no idea why i just can't get SMTP to work....

    As for using SPUtility.SendEmail... I would have thought it would be the user's context to send the email? If the user could send the email to the group via Outlook, why is that it can't get passed the authentication?...hm...

    Monday, October 15, 2012 3:05 AM
  • Monday, October 15, 2012 3:32 AM
    Moderator
  • Is there a way i can use the user's context? Or force the code to run on a particular service account?
    Monday, October 15, 2012 3:56 AM
  • I have this

    //send via smtp
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    SmtpClient SmtpServer = new SmtpClient("my.servername.com"); 
    mail.From = new MailAddress(strFromAddress);
    mail.To.Add(toAddress);
    mail.Subject = subject;
    mail.Body = message;
    SmtpServer.UseDefaultCredentials = true;
    SmtpServer.Send(mail);
    But the emails seem to get stuck in the C:\inetpub\mailroot\Queue folder.

    Monday, October 15, 2012 4:20 AM
  • You are looking for something like this: SmtpServer.Credentials = new NetworkCredential("user", "password"); 

    instead of: SmtpServer.UseDefaultCredentials = true;


    Patrick Curran | Twitter | Blog
    Click "Mark as Answer" on the post that helps you.
    Click "Unmark as Answer" if a marked post does not actually answer your question.
    Click "Vote As Helpful" if a post has been useful to you.

    Monday, October 15, 2012 4:33 AM
  • thanks...
    Monday, October 15, 2012 5:33 AM
  • Hmm... but in production, there will be different people everytime, and I won't be able to have their password detail? Unless I use a service account to do this? What permission does this account have? Is that something I have to add in SMTP server settings?
    Monday, October 15, 2012 5:42 AM
  • You will just pass a valid Domain user account (service account).  Keep in mind this is generally passed to the SMTP server in cleartext, and it isn't advisable to put a cleartext password in code, either.

    SharePoint - Nauplius Applications
    Microsoft SharePoint Server MVP - 2012

    Monday, October 15, 2012 5:43 AM
    Moderator
  • What sort of permission level should this service account have?

    Monday, October 15, 2012 5:50 AM
  • Any domain user account will do.  It doesn't need special rights.

    SharePoint - Nauplius Applications
    Microsoft SharePoint Server MVP - 2012

    Monday, October 15, 2012 5:50 AM
    Moderator