C# NET PROGRAMMING SENDING EMAIL WITH MANUAL SETTING SMTP – SAMPLE CODE

   

SENDING EMAIL WITH MANUAL SETTING SMTP – Karena kebutuhan user untuk kirim email pada aplikasi yang kita buat menggunakan bahasa C# dekstop maupun website, berikut ini saya berikan contoh fungsi untuk menngirim email menggunakan net programmming C#:

void bool _sendmail( string smtp_client, string send_mail_addr, string to_mail_addr, string subj, string _body, string smtp_uname, string smtp_pass)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient(smtp_client);
                mail.From = new MailAddress(send_mail_addr);
                mail.To.Add(to_mail_addr);
                mail.Subject = subj;
                mail.Body = _body;
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential(smtp_uname, smtp_pass);
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

cara menjalankan fungsi tersebut adalah sebagai berikut:

_sendmail("ilmuprogram.com", "username@ilmuprogram.com", "wahyukitech@gmail.com", "TEST", "BODY", "username@ilmuprogram.com", "password");

Hasilnya adalah sbb:

Demikian tutorial pada artikel ini, semoga dapat membantu.

Wahyu Amaldi, M.Kom has written 87 articles

Hi Reader, thank you for read this article, i hope this article can be useful.
If you will share knowladge to me, dont forget contact to me.

Email 1 : wahyu.amaldi@outlook.com
Email 2 : wahyu.amaldi@ilmuprogram.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>