Click here to Skip to main content
16,022,189 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am sending Email from My C# code to Oracle Cloud Infrastructure Email But it's giving me Following Error

Error: "The server response was: Authentication required|Inner Exception"

Following is my Code

try
{
    // Retrieve SMTP configuration from web.config
    string smtpHost = ConfigurationManager.AppSettings["SMTPHost"];
    int smtpPort = int.Parse(ConfigurationManager.AppSettings["SMTPPort"]);
    string senderEmail = ConfigurationManager.AppSettings["SenderEmail"];
    string senderID = ConfigurationManager.AppSettings["SenderUser"];
    string senderPassword = ConfigurationManager.AppSettings["SenderPwd"];

    // Define the recipient, subject, and body of the email
    string recipientEmail = "akki@gmail.com";
    string subject = "Test Email From New Details";
    string body = "This is a test email sent from ASP.NET MVC.";

    // Create a new MailMessage object
    using (MailMessage mail = new MailMessage())
    {
        mail.From = new MailAddress(senderEmail);
        mail.To.Add(recipientEmail);
        mail.Subject = subject;
        mail.Body = body;
        mail.IsBodyHtml = true;

        // Create a new SmtpClient object
        using (SmtpClient smtpClient = new SmtpClient(smtpHost, smtpPort))
        {
            smtpClient.UseDefaultCredentials = false;
            //smtpClient.Credentials = new NetworkCredential(senderEmail, senderPassword);
            smtpClient.Credentials = new NetworkCredential(senderID, senderPassword);
            smtpClient.EnableSsl = true; // Ensure this matches the server's SSL requirements

            // Send the email
            smtpClient.Send(mail);
            //ViewBag.Message = "Email sent successfully!";
        }
    }
}
catch (SmtpException smtpEx)
{
    // Log SMTP specific errors
    //ViewBag.Message = $"SMTP Exception: {smtpEx.Message}";
    Console.WriteLine(smtpEx.Message);
}
catch (Exception ex)
{
    // Log general errors
    //ViewBag.Message = $"General Exception: {ex.Message}";
    Console.WriteLine(ex.Message);
}


Following is orcal cloud configuration

<pre><add key="SMTPHost" value="smtp.email.ap-mumbai-1.oci.oraclecloud.com" />


<add key="SMTPPort" value="587" />


What I have tried:

i have treid many thing didnt find code
Posted
Updated 30-Jul-24 7:19am
v2
Comments
Akshay malvankar 30-Jul-24 13:20pm    
Can anyone here implement this Oracle Cloud Infrastructure Email in C#
Akshay malvankar 31-Jul-24 1:40am    
hello can anyone here to help me on this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900