Click here to Skip to main content
15,888,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm having a little issue with my sendmail script. My mail can't be delivered to one of my internal distribution lists. Other DL are receiving the mail. I'm getting the returned message:
RESOLVER.RST.AuthRequired; Authentication required

My c# code looks like this (method SendMail belongs to a class named Plan):

C#
public void SendMail(int supplierValue, List<Location> locationList, string meldingsNr, string date, string fromT, string tillT)
    {
    var mailFrom = "mail@mail.com";
    SmtpClient client = new SmtpClient("server ip",25);
    client.UseDefaultCredentials = false;
    NetworkCredential basicAuthInfo = new NetworkCredential("username", "password");
    client.Credentials = basicAuthInfo;
    client.EnableSsl = false;

    // Create some empty vars

    var toList = "";
    var ccList = "";
    var mailSubject = "";
    var mailBody = "";
    List<string> locationListString = new List<string>();
    List<string> locationListString2 = new List<string>();

    // Populate toList with var llString

    ** code removed **

    // switch on supplier Value to fill toList, ccList and mailSubject

    ** code removed **

    // Create mail message

    MailMessage message = new MailMessage();
    MailAddress mailAddress = new MailAddress(mailFrom);
    message.To.Add(toList);
    message.From = mailAddress;
    message.CC.Add(ccList);

    // set subject and encoding

    message.Subject = mailSubject;
    message.SubjectEncoding = Encoding.UTF8;

    // set body and encoding

    message.Body = mailBody;
    message.BodyEncoding = Encoding.UTF8;
    message.IsBodyHtml = true;

    try
    {
        // Send mail 
        client.SendCompleted += (s, e) =>
        {
            client.Dispose();
            message.Dispose();
        };
        client.SendAsync(message, null);

    } catch (SmtpException ex)
    {
        MessageBox.Show(ex.InnerException.Message);

    } catch (System.Exception ex)
    {
       MessageBox.Show(ex.InnerException.Message);
    }
}


What I have tried:

i tried applying this solution:
authentication - How can I make SMTP authenticated in C# - Stack Overflow[^]

Make sure you set SmtpClient.Credentials after calling SmtpClient.UseDefaultCredentials = false. The order is important as setting SmtpClient.UseDefaultCredentials = false will reset SmtpClient.Credentials to null.

but this didn't work. Is there anything else wrong with my code ?
Posted
Comments
Richard Deeming 9-May-17 9:18am    
Sounds like Exchange thinks your message is originating from outside of your network, and isn't authenticated.

There's an option on the "Mail Flow Settings" tab to turn off the authentication requirement, but you probably don't want to do that.

See if this ServerFault answer[^] helps.
Member 13188273 9-May-17 9:45am    
No i don't want to do that :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900