Answers for "c sharp send email"

C#
8

c# send email

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());
            }
        }
    }
}
Posted by: Guest on March-13-2020
0

send mail in c#

public void SendMail(string toEmail, string subject, string body, bool isBodyHtml = true)
                {
                    try
                    {
                        using (MailMessage mail = new MailMessage())
                        {
                            mail.From = new MailAddress("", "R3Investment Group");
                            mail.To.Add(new MailAddress(toEmail));
                            mail.Subject = subject;
                            mail.Body = body;
                            mail.IsBodyHtml = isBodyHtml;
                            using (SmtpClient smtp = new SmtpClient("smtp.office365.com", 587))
                            {
                                smtp.Credentials = new NetworkCredential("", "");
                                smtp.EnableSsl = true;
                                smtp.Send(mail);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
Posted by: Guest on November-05-2021

C# Answers by Framework

Browse Popular Code Answers by Language