© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
S-IERRA

❔ SmptClient invalid response to the EHLO command.

I have 2 versions of this project one is one console which works perfectly well the other one is on Asp.net which is always receiving

"The server returned an invalid response to the EHLO command."

The code is pretty much identical across the both of them I assume it could be asp blocking the request?

Asp.net src (not working)
    private async Task<bool> SendAsync(string recipientEmail, string subject, string body)
    {
        const string senderEmail = "removed"; // Your Gmail email address
        const string senderPassword = "removed"; // Your application-specific password

        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new NetworkCredential(senderEmail, senderPassword);
        
        var mailMessage = new MailMessage(senderEmail, "removed@gmail.com", "test", "test2");
        mailMessage.IsBodyHtml = true;
        
        await smtpClient.SendMailAsync(mailMessage);
    }
    private async Task<bool> SendAsync(string recipientEmail, string subject, string body)
    {
        const string senderEmail = "removed"; // Your Gmail email address
        const string senderPassword = "removed"; // Your application-specific password

        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new NetworkCredential(senderEmail, senderPassword);
        
        var mailMessage = new MailMessage(senderEmail, "removed@gmail.com", "test", "test2");
        mailMessage.IsBodyHtml = true;
        
        await smtpClient.SendMailAsync(mailMessage);
    }


Console app Src (working)

public class MailService
{
    private const string SenderEmail = "removed"; // Your Gmail email address
    private const string SenderPassword = "removed"; // Your application-specific password

    private readonly SmtpClient _smtpClient = new SmtpClient("smtp.gmail.com", 587);

    public MailService()
    {
        _smtpClient.EnableSsl = true;
        _smtpClient.UseDefaultCredentials = false;
        _smtpClient.Credentials = new NetworkCredential(SenderEmail, SenderPassword);
    }

    public async Task<bool> SendAsync(string recipientEmail, string subject, string body)
    {
        var mailMessage = new MailMessage(SenderEmail, recipientEmail, subject, body);
        mailMessage.IsBodyHtml = true; 

        await _smtpClient.SendMailAsync(mailMessage);
    }
}
public class MailService
{
    private const string SenderEmail = "removed"; // Your Gmail email address
    private const string SenderPassword = "removed"; // Your application-specific password

    private readonly SmtpClient _smtpClient = new SmtpClient("smtp.gmail.com", 587);

    public MailService()
    {
        _smtpClient.EnableSsl = true;
        _smtpClient.UseDefaultCredentials = false;
        _smtpClient.Credentials = new NetworkCredential(SenderEmail, SenderPassword);
    }

    public async Task<bool> SendAsync(string recipientEmail, string subject, string body)
    {
        var mailMessage = new MailMessage(SenderEmail, recipientEmail, subject, body);
        mailMessage.IsBodyHtml = true; 

        await _smtpClient.SendMailAsync(mailMessage);
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Slash Command response to specific channel
C#CC# / help
4y ago
❔ Default command in System.CommandLine
C#CC# / help
3y ago
Passing a string property to a command via a button CommandParameter in .NET 6
C#CC# / help
4y ago
How to implement code for a Client to invoke a command from the command line
C#CC# / help
11mo ago