Share via

SMTP Email not going from Asp.net C# Project

Anonymous
2021-05-27T14:26:34+00:00

Hi,

I am trying to send email from Asp.net Project. I have tried all available options but no success.

I have already changed SMTP = Authentication true in Exchange.

ERROR : "Failure Sending Email"

Below is code, I am using

try

            {

                MailMessage Msg = new MailMessage();

                // Sender e-mail address.

                Msg.From = new MailAddress("******@gxxxxxoin.com"); <Modified by moderator due to privacy>

                // Recipient e-mail address.

                Msg.To.Add(txtTo.Text);

                Msg.Subject = txtSubject.Text;

                Msg.Body = txtBody.Text;

                // your remote SMTP server IP.

                SmtpClient smtp = new SmtpClient();

                smtp.Host = "gxxxxxoin-com.mail.protection.outlook.com"; ----- Trying with MX Record

                //   smtp.Host = "smtp.office365.com"; -------- We have also tried with this setting.

                smtp.Port = 587;

                smtp.UseDefaultCredentials = false;

                smtp.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtpwd.Text);

                smtp.EnableSsl = true;

                smtp.Send(Msg);

                Msg = null;

                Label1.Text = "sucess";

                Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='SendMail.aspx';}</script>");

            }

            catch (Exception ex)

            {

                Label1.Text = ex.Message;

            }

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-05-27T15:52:10+00:00

    Hi Ved,

    Thank you for posting. Make sure if you are using SMTP client submission that requires authentication Microsoft 365 or Office 365 username and password required licensed mailbox.

    If you are using SMTP relay which need one or more static IP addresses and your LOB app must have a static IP address to use for authentication with Microsoft 365 or Office 365.

    Here's the article which has mentioned comparison of each configuration option and the features they support. See Compare the options

    Since you are using Asp.net C# code therefore, I would like to involve our dedicated support team please post your issue in the dotnet-csharp on Microsoft Q&A forum so there experts’ will focus on the issue to get it resolved more efficiently.

    Regarding this point, we would truly appreciate your kind understanding. Have a nice day and stay safe!

    Best regards,

    Shyamal

    Was this answer helpful?

    0 comments No comments