sending email using c#

using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("to_address");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

0
0

                                    using System.Net;
using System.Net.Mail;
using System.Net.Mime;

...
try
{

   SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
   System.Net.NetworkCredential basicAuthenticationInfo = new
      System.Net.NetworkCredential("username", "password");
   mySmtpClient.Credentials = basicAuthenticationInfo;

   // add from,to mailaddresses
   MailAddress from = new MailAddress("[email protected]", "TestFromName");
   MailAddress to = new MailAddress("[email protected]", "TestToName");
   MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

   // add ReplyTo
   MailAddress replyTo = new MailAddress("[email protected]");
   myMail.ReplyToList.Add(replyTo);

   // set subject and encoding
   myMail.Subject = "Test message";
   myMail.SubjectEncoding = System.Text.Encoding.UTF8;

   // set body-message and encoding
   myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
   myMail.BodyEncoding = System.Text.Encoding.UTF8;
   // text or html
   myMail.IsBodyHtml = true;

   mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
  throw new ApplicationException
    ("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
   throw ex;
}

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# best way to send email sending email in cSharp sending a email using client email client c# send email in console application c# getting email using asp.net c# how to send email from c# asp.net sending an email using asp.net c# send email with file in c# Email Send software c# microsoft send email via c# c# form send email how to send mail with c# c# send email script send email function c# c# send email in html send an email from c# send email in csharp how to receive an email in c# mail in c# using company email sending an email using c# c# using mail address send email c# asp.net c# send email with mailkit send email using c# with smtp send email from C# code send email asp.net c# c# send email using smtp send email library c# send to mail using c# .net send to mail using c# how to send email using console application in c# how to send email using c# asp.net send email to someone in .net c# c sharp send email email creation in C# send email from own server c#.net code to send email in c# how to set email sender in c# send email c# using mail command email creation c# program api send email c# send email using web api c# C# sending mail with email client c# send email function send email with mailjet mvc c# c# send a email sending out mail c# how to send emails using c# C# send email https send email using c# asp.net send email through c# code c# + Email sending sample send email c# console application send email using asp.net c# how to send mail c# c# send email with template request email in c# sending email from console application c# sending an email in c# c # send mail how to send an email with c# how to read email using c# how to send a mail using c# c# send email console application c# send email with style c# send smtp email how to send a mail with c# how to send emails in c# email.from c# send email c# function sending email programmatically c# send email with html c# send mail from code c# c# email sender send mail c sharp enable sending email via c# c# send email MICROSOFT send mail with c# how to send a mail in c# csharp email send c# how to read and send emails send mail using c# asp.net send mail from asp.net c# send email c# code send email with c sharp- send mail with c sharp- send email from c# .net 5 sending mail in asp.net using c# send email through c# c# asp.net send email c# html email send send html email c# c# send email console send mail in asp.net c# c# write email how to send email with c# send email class c# send email api c# send email from c# web application email sending functionality in c# c# .net send email c# how to send html email send emails c# how to send email using asp.net c# c# best send email send an email from c# asp.net using code in send email c# how to pass a email from c# send html email in c# basic email using C# how to send email by c# send email smtp in c# c# send email with attachment email sending script in c# c# sendo email C# send email 2020 c# send email mailkit c# send mail mailkit c# twilio send sms c# validate email send email C3 c# console send email smtp email code c# how to send data in gamil in c# c# send email without smtp C# email write how to send mail in c# c# "how do apps send email" c# send MainMessage how to send an mail in windows form using c# with sourcecode how to send email in c# send email through c# using my server create email with attachment c# c# email program how to send an email c# System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) send email on C# new email() c# c# sending email with smtp send outlook emails in C# send outlook email in C# C# how to send emails send email sendinblue C# c# smtpclient can have invalid from value how to send an email from c# code with attachment how to send an email from c# code send gmail c# C# send email with gmail c# send email html with images mail code in c# email sender c# send and verify OTP using send email in C# using C# to create a email server client.send c# sending email from c# Unable to send mail. using .net c# email message send c# send email github c# send email service how to create an email using C# send email via c# how to send mail using smtp server in c# download send simple email c# mailing in C# c# email smtp mail in c# smtp send email c# C# send email from your app c# generic class for sending email c# send html email tool for email sender C# .net send email smtp send mail by smtp c# how to send an email in c# send file in an email c# smtp mail from c# smtp client c# how send email c# smtp email c# sending email template c# sending html email using c# smtp webmail c# c# email someone how to send email using sendgrid in c# send email with tls c# email send in c# how to send email from webmail in c# mailbody.sender c# send email using c# with proper format sendmail c# smtp mail server in c# email notification in c# how to sent email in C# creating Email using c# send-only email address using c# how to get email c# gmail smtp connection string sending email in c# sending email in c# web application send emails with c# send mail .net how to pass in an email into C# send mail c# c# how to send email with smtp client c# send an email c# how to email how to send emails with c# how to send email using c3 send an email via c# can send email with smtp c# how to send mail using smtp server in c# smtp c# create an email delivery app c# sending email with c# smtp.Connect in c# for webmail send mail in c# c# smtp send email sample C# email code c# how to send email email sending c# send email using smtp in c# c# sending an email how to send automatic Email/Message using C# how to send automatic Email using C# how to send a mail in csharp c# send emai how to send emails c# config email account for send mail c# send c# email how to send an email using c# c# send email from smtp c# code send email how to send email c# send mail .net sample c# c# sending email no form sending an email c# ~ form send email from c# how to write code to send email in c# c# mail script Email trigger code in c# mail sending code in c# how to send mails in C# mail.from c# send smpt mail C# c# smpt send sample app smtp client send email c# create an email service in c# smtp send mail c# c# send alert email sending an email c# send email c# .net how to send ~ using c# database based email solution on c# send an email c# c# send mail email service for c# c# mail procedure c# code to send an email c# sending email good smtp server for c# send email service c# c# to send mail c# create email config c# method to send email c# xsend email how to send email using c# send email using c# email send code in c# free smtp client c# sending a email in C# how to send a email in c# send email in c# send smtp email C# email c# mail c# c# create email service Send mailusing c# how to send an mail in c# send email c# send e-mail c# how to swnd email using c# smtp c# send email sending emails in c# c# mailer how to send email from c# send a mail using c# send mail using c# c# interface send email smtp c# send email interface sending email c# free smtp c# email notification library for desktop apps with templating how to send mail from client mail to comapny mail c# how to write an email in c# c# code for sending email send email for free to my email c# c# code to send email automatically email in c# send emails in c# send free email to user smtp c# code send email with c# c# send email smtp C# sending mail c# send email c# send email from application sending email using smtp c# C# send emails c# send email example c# program to send email c# email send c# how to send an email asending an email in c# c# email sending code send email from .net application c# send gmail using python c# code to send email send mail using php send an email in c# mail send c# sned emails in c# sending email using c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source