C
C#16mo ago
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, "[email protected]", "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, "[email protected]", "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);
}
}
2 Replies
S-IERRA
S-IERRAOP16mo ago
Closing this issue as I fixed it, the issue was due to System.Net.Mail SmptClient being obsolete but no one marking it as so, mailkit should be used instead, possibly someone could update smptclient to be marked as obsolete in code? it is only commented as so but doesnt give a warning
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server