'The SMTP server requires a secure connection or the client was not authenticated - Error
I am trying to send email using Amazon SES.
I am able to send email by using our local SMTPserver and also able to send email by using sample provided at amazon website.
I need to send send From Address & To Address names with the email. I can not do this with SendEmailRequest class provided in the Amazon SDK, because there is no such overload for WithSource(toaddress), WithDestination(destinationaddress) & WithReplyToAddresses(replytoaddress) methods so i can't pass names form sender 7 receiver here, so that I am using regular method of sending mail using Amazon configurations.
I tried both way pass credentials by the hard coding through code as well as by puyting configuration by file but still I am getting same error for both ways above this error when using port 587,
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required"
when tried with 465 port getting this error, "Failure Sending Email"
When tried putting IP address instead of host address of amazon server got this error.
"The remote certificate is invalid according to the validation procedure."
Please suggest me what I am missing here,
Here is my code,
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress(FromEmail, FromName);
SmtpClient smtp = new SmtpClient("email-smtp.us-east-1.amazonaws.com", 587);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential(AWSAccessKey, AWSSecretKey);
//recipient address
mail.To.Add(new MailAddress(ToEmail, ToName));
//Formatted mail body
mail.IsBodyHtml = true;
mail.Body = strBody;
smtp.Send(mail);
Thanks in Advance..!!!
Solution 1:[1]
I solved this problem by passing email with email user name in the following in the format
User Name< [email protected] >
Sample from Amazon site is already working for me,
here is my working code,
AWSCredentials objAWSCredentials = new BasicAWSCredentials(AWSAccessKey, AWSSecretKey);
Destination destination = new Destination().WithToAddresses(new List<string>() { TO });
// Create the subject and body of the message.
Content subject = new Content().WithData(SUBJECT);
Content textBody = new Content().WithData(BODY);
Body body = new Body().WithHtml(textBody);
//Body body = new Body().WithText(textBody);
// Create a message with the specified subject and body.
Message message = new Message().WithSubject(subject).WithBody(body);
// Assemble the email.
SendEmailRequest request = new SendEmailRequest().WithSource(FROM).WithDestination(destination).WithMessage(message).WithReplyToAddresses(REPLYTO);
// Instantiate an Amazon SES client, which will make the service call. Since we are instantiating an
// AmazonSimpleEmailServiceClient object with no parameters, the constructor looks in App.config for
// your AWS credentials by default. When you created your new AWS project in Visual Studio, the AWS
// credentials you entered were added to App.config.
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(objAWSCredentials);
// Send the email.
Console.WriteLine("Attempting to send an email through Amazon SES by using the AWS SDK for .NET...");
client.SendEmail(request);
here I've passed FROM, TO & ReplyToAddress in this format, User Name< [email protected] >
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
