0

I have recently moved the web app from one server to another. No changes in the code or web config (apart from database connection) has been done.

In the old server, the application could send emails. In the new server, this error arises. Is there a configuration that I am missing here? I looked in IIS Manager, and the SMTP Email is not even activated in the old server. It seems to be an authentication issue, I do not know how the authentication works in this case.

I have not done the configuration in the old server so I do not know where to look.

public MailHelper(string sender, string recipient)
{
    NetworkCredential cred = new NetworkCredential(SmtpUser, SmtpPassword); 
    message = new MailMessage(sender, recipient); 
    client = new SmtpClient(); 
    client.Port = 25; 
    client.DeliveryMethod = SmtpDeliveryMethod.Network; 
    client.UseDefaultCredentials = true; 
    client.Host = SmtpHost;
}

public void Send(string subject, string body) 
    { 
        message.Subject = subject; 
        message.IsBodyHtml = true; 
        message.Body = body; 
        client.Send(message); 
    }

What are my next steps?

Cheers.

image of stacktrace: https://ibb.co/fd2jwPG

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • What library are you using to send the e-mail? – the.Doc May 21 '20 at 08:20
  • Check SMTP configuration and also check once with IT team – Always_a_learner May 21 '20 at 08:36
  • @the.Doc I am using SmtpClient.Send – DevTropical May 21 '20 at 08:47
  • @user13422309 The SMTP configuration is in the IIS Manager right? In the old server it is not even added in IIS. So I guess it is using the default configuration. I wonder if there's a need for certificates or something like that. – DevTropical May 21 '20 at 08:48
  • Probably have to do with the settings on your email server - they not allow you to send emails unless you have first authenticate - check your email server – Aristos May 21 '20 at 08:50
  • @DevTropical basically organization SMTP (email service server)is configured by IT team, so i would suggest chek once with your IT team that is there any change with SMTP configuration. Moreover you can share email sendign code here – Always_a_learner May 21 '20 at 08:51
  • Possible duplicate -> https://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated/38024407 – Aristos May 21 '20 at 08:52
  • @Aristos how do I check the settings in the email server? The application is currently hosted in windows server 2012 and the old server was hosted in windows server 2008. In the old server where it worked, in IIS, SMTP Email is not even activated. – DevTropical May 21 '20 at 09:53
  • @user13422309 Im not sure how snippets are shared here but here goes: – DevTropical May 21 '20 at 10:00
  • public MailHelper(string sender, string recipient) { NetworkCredential cred = new NetworkCredential(SmtpUser, SmtpPassword); message = new MailMessage(sender, recipient); client = new SmtpClient(); client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = true; client.Host = SmtpHost; } – DevTropical May 21 '20 at 10:03
  • public void Send(string subject, string body) { message.Subject = subject; message.IsBodyHtml = true; message.Body = body; client.Send(message); } – DevTropical May 21 '20 at 10:03
  • Create an e-mail account on your server, using probably your host panel, then use this email to authenticate and send your emails base on that one (as sender) - Edit your question to add your code please – Aristos May 21 '20 at 10:49

0 Answers0