Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:19:46+00:00 2026-05-23T17:19:46+00:00

I need to send mail using Gmail SMTP, but it’s showing Failure sending mail.

  • 0

I need to send mail using Gmail SMTP, but it’s showing Failure sending mail.,

can you please help?

   <system.net>
    <mailSettings>
      <smtp from="myn@gmail.com ">
        <network host="smtp.gmail.com" defaultCredentials="false"
      port="587" userName ="myn@gmail.com" password="pass@123" />
      </smtp>
    </mailSettings>
   </system.net>


    public string SendEmail(bool readWebConfig)
    {
        string emailStatus = string.Empty;

        string from = "myn@gmail.com"; //Replace this with your own correct Gmail Address

        //Replace this with the Email Address to whom you want to send the mail
        string to = "myn@yahoo.com";
        string cc = "";
        string bcc = "";

        string fromName = "bryian";
        string userName = "myn@gmail.com";
        string password = "pass@123";

        Attachment attachment = null;

        //if you want to send attachment, include the file location
        // Attachment attachment = new Attachment("file location");

        SmtpClient client = new SmtpClient();
        client.EnableSsl = true; //Gmail works on Server Secured Layer

        if (!readWebConfig)
        {
            client.Credentials = new System.Net.NetworkCredential(userName, password);
            client.Port = 587; // Gmail works on this port
            client.Host = "smtp.gmail.com"; //hotmail: smtp.live.com
        }

        try
        {
            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(from, fromName);
                mail.ReplyTo = new MailAddress(from, fromName);
                mail.Sender = mail.ReplyTo;

                if (to.Contains(";"))
                {
                    string[] _EmailsTO = to.Split(";".ToCharArray());
                    for (int i = 0; i < _EmailsTO.Length; i++)
                    {
                        mail.To.Add(new MailAddress(_EmailsTO[i]));
                    }
                }
                else
                {
                    if (!to.Equals(string.Empty))
                    {
                        mail.To.Add(new MailAddress(to));
                    }
                }

                //CC
                if (cc.Contains(";"))
                {
                    string[] _EmailsCC = cc.Split(";".ToCharArray());
                    for (int i = 0; i < _EmailsCC.Length; i++)
                    {
                        mail.CC.Add(new MailAddress(_EmailsCC[i]));
                    }
                }
                else
                {
                    if (!cc.Equals(string.Empty))
                    {
                        mail.CC.Add(new MailAddress(cc));
                    }
                }

                //BCC
                if (bcc.Contains(";"))
                {
                    string[] _EmailsBCC = bcc.Split(";".ToCharArray());
                    for (int i = 0; i < _EmailsBCC.Length; i++)
                    {
                        mail.Bcc.Add(new MailAddress(_EmailsBCC[i]));
                    }
                }
                else
                {
                    if (!bcc.Equals(string.Empty))
                    {
                        mail.Bcc.Add(new MailAddress(cc));
                    }
                }

                string message = "this is a test message";

                mail.Subject = "test subject";

                mail.Body = "<div style=\"font: 11px verdana, arial\">";
                mail.Body += message.Replace("\n", "<br />") + "<br /><br />";
                mail.Body += "<hr /><br />";
                mail.Body += "<h3>Sender information</h3>";
                mail.Body += "<div style=\"font-size:10px;line-height:16px\">";
                mail.Body += "<strong>Name:</strong> " + fromName + "<br />";
                mail.Body += "<strong>E-mail:</strong> " + from + "<br />";
                mail.IsBodyHtml = true;

                if (HttpContext.Current != null)
                {
                    mail.Body += "<strong>IP address:</strong> " + HttpContext.Current.Request.UserHostAddress + "<br />";
                    mail.Body += "<strong>User-agent:</strong> " + HttpContext.Current.Request.UserAgent;
                }

                //attachment
                if (attachment != null)
                {
                    mail.Attachments.Add(attachment);
                }

                client.Send(mail);
                emailStatus = "success";
            }
        }

        catch (Exception ex)
        {
            emailStatus = ex.Message;
        } // end try 

        return emailStatus;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string status = SendEmail(false);
        Response.Write(status);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:19:47+00:00Added an answer on May 23, 2026 at 5:19 pm

    I have tried your code and it works fine for me(with my credentials). Did you tried by disabling the firewall or antivirus? what the inner exception says?

    Steps to disable:

    Windows XP Firewall

    Windows 7 Firewall

    Antivirus

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for this app i'm following this example: http://pipoltek.blogspot.com/2008/02/sending-mail-using-gmail-smtp-server.html I can send emails, it looks
how to send rich text message in system.net.mail need code for send a mail
I need to send hundreds of newsletters, but would like to check first if
We need to send email which contains Pound (currency) symbols in ColdFusion. Before sending
I need to send a CSV file in HTTP response. How can I set
Situation: I need to make an imap client (using java mail api) that if,
I am trying to send email through gmail using PHPMailer_V5.1. Getting the following error,
How can i send html mail with images in c#? Can i just set
I need to send and receive data over serial connections (RS-232 and RS-422). How
I need to send MMS thought a C# application. I have already found 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.