hello everyone. for contactus in C# asp net webform, i have used sendgrid and for that the following codes:
protected async void btnSend_Click(object sender, EventArgs e)
{
emailfrom = txtEmail.Text;
sub = txtSubject.Text;
body = txtBody.Text;
await Execute().ConfigureAwait(false);
}
static async Task Execute()
{
var apiKey = "my key";
var client = new SendGridClient(apiKey);
var from = new EmailAddress(emailfrom, "someone");
var subject = sub;// "Sending with SendGrid is Fun";
var to = new EmailAddress("[email protected]", "venus");
var plainTextContent = body;// "and i check if it works";
var htmlContent = "" + body + "";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
System.Diagnostics.Debug.WriteLine(response.StatusCode);
System.Diagnostics.Debug.WriteLine(response.Body.ReadAsStringAsync());
i get error: An existing connection was forcibly closed by the remote host
i appreciate your help to fix this error... i dont know how to eventually fix SSL or TSL
Abhishek YadavPosted Aug 10, 2024, 4:40 AM
Thank you for your patience. Regarding the issue with SendGrid in your C# ASP.NET WebForm project, the error "An existing connection was forcibly closed by the remote host" typically indicates a problem with SSL/TLS settings or network connectivity.
Here’s a revised approach to address this issue:
Update SendGrid Package: Ensure that you are using the latest version of the SendGrid NuGet package. Sometimes, updating to the latest version can resolve SSL/TLS issues.
Check SSL/TLS Settings: Verify that your application is configured to use the appropriate SSL/TLS version. You can enforce TLS 1.2 by adding the following code to your application startup
Verify API Key: Double-check your SendGrid API key to ensure it's correct and has not expired or been revoked.
Inspect Firewall and Proxy Settings: Ensure that your network firewall or proxy settings are not blocking the connection to SendGrid's servers.
Here’s a sample code snippet incorporating these suggestions:
venus najadPosted Aug 10, 2024, 7:05 AM
dear Abhishek Yadav
thanks for your respond, it works now. kind regards