Send Email by C#

I need a code for Winform application that would send email to the user within the company exchange email address. The users in company are setup with exchange in outlook. Please help if it is possible for you.

Thank you,
PE
pauledwardianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, This is the example of mail sending in winform applications.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net.Mail;

namespace YourProjectName
{
    public partial class feedback : Form
    {
        public feedback()
        {
            InitializeComponent();
        }

        private void feedback_Load(object sender, EventArgs e)
        {
           
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string sTo = "abc@abc.com";
            string sFrom = txtEmail.Text;
            string sSubject = txtName.Text;
            string sBody = txtHow.Text;

            try
            {
                MailMessage mail = new MailMessage(sFrom, sTo, sSubject, sBody);
                SmtpClient client = new SmtpClient("192.168.1.1"); //Your smtpclient
                client.Send(mail);
                MessageBox.Show("Mail Successfully Sent");
                txtName.Text = "";
                txtEmail.Text = "";
                txtContactNo.Text = "";
                txtHow.Text = "";
            }
            catch (Exception)
            {
                MessageBox.Show("Mail Sending Fail");
            }
        }
    }
}

You also require to add this into app.config file of your project. The host name will be in your outlook account.

<system.net>
            <mailSettings>
                  <smtp>
                        <network host="mx.abc.com" port="25" userName="abc@abc.com" password=""/>
                  </smtp>
            </mailSettings>
            
      </system.net>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pauledwardianAuthor Commented:
Can the username and password gets generated either by taking the username and password from the windows login (that user uses to login to his computer) or by prompting for a username and password for the user to input his credentials.
Basically I need to have my application install on each Users computer and then have the program to automatically send that particular user an email address like a reminder.
0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Respected Sir,

Can you give me some time for this solution, I will give you a answer as early as possible. Thank you for reply me.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

nishant joshiTechnology Development ConsultantCommented:
good code by @samir


add only one line,

client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
0
pauledwardianAuthor Commented:
Sure, take your time. :)
Thanks  nishantcomp2512 for your suggestion by the way.
0
pauledwardianAuthor Commented:
Hello Samir,

Thanks for helping me on this question. I was just checking to see if you could find the solution.

PE
0
Nitesh LuharukaDirectorCommented:
@paul, yes you can always take the username and password from winform application instead of app.config file.
0
pauledwardianAuthor Commented:
Thanks guys for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.