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 8962581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:09:33+00:00 2026-06-15T16:09:33+00:00

For my application I have code to send emails for live/hotmail, but not for

  • 0

For my application I have code to send emails for live/hotmail, but not for gmail, that doesn’t work I tried to build a check for it, to see what account is used to send the e-mail but it’s not working, when I try to send an Gmail email. Here is the code I use for the check:

MailMessage msg = new MailMessage();
            msg.To.Add(txtAan.Text);
            msg.From = new MailAddress(txtGebruikersnaam.Text);
            msg.Subject = txtOnderwerp.Text;
            msg.Body = txtBericht.Text;

            string smtpcheck = txtGebruikersnaam.Text;
            smtpcheck.Substring(Math.Max(0, smtpcheck.Length - 10));

            SmtpClient smtp = new SmtpClient();
            if (smtpcheck.ToLower() == "@gmail.com")
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 25;
            }
            else if(smtpcheck.ToLower() != "@gmail.com")
            {
                smtp.Host = "smtp.live.com";
                smtp.Port = 587;
            }
            smtp.EnableSsl = true;
            smtp.Credentials = new NetworkCredential(txtGebruikersnaam.Text, txtWachtwoord.Text);
            smtp.Send(msg);

This code gives me an error when I try to send an E-mail by using Gmail, can somebody give me a little help with this problem? And yes I also tried the port: 465 and 587 for gmail, so I don’t think that is the problem either.

  • 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-06-15T16:09:35+00:00Added an answer on June 15, 2026 at 4:09 pm

    This line doesn’t change the value of smtpcheck

      smtpcheck.Substring(Math.Max(0, smtpcheck.Length - 10));
    

    you need to write

      smtpcheck = smtpcheck.Substring(Math.Max(0, smtpcheck.Length - 10));
    

    As result your if condition fails and you fall to send the mail always with live.com

    EDIT: For gmail, this code is confirmed to work

     SmtpClient sc = new SmtpClient("smtp.gmail.com");
     NetworkCredential nc = new NetworkCredential("username", "password");
     sc.UseDefaultCredentials = false;
     sc.Credentials = nc;
     sc.EnableSsl = true;
     sc.Port = 587;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code in the top layer of my .Net web application that I'd
I'm moving an application to use the Spring3 framework and I have code that
I have an application where I can send emails. Now am asked to use
I have a console application that sends customized emails (with attachments) to different recipients
I'm using python 2.7.3. and I have following code for send emails with attached
I have a small WinForms application that sends notification emails. It works fine with
i looking for code to send an email from my android application. I have
I have created some code that emails an html email to a given address.
it's a clean-code type question. application sends emails on appropriate addresses. but when variable
I have an ASP.Net/MVC application and I'm trying to send HTML emails. I'm doing

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.