C# Program Send Mail Google

Postingan kali  ini ane coba akan buat postingan yang berbau coding - coding gitu :) Setelah sekian lamanya kagak pernah memposting sesuatu tentang pemrograman :D
Bahasa pemrograman yang ane gunakan kali ini juga gak jauh beda sama dengan bahasa pemrograman di postingan tentang pemrograman terdahulu, ya masih dalam keluarga bahasa C, yaitu C#. C# memang ada yang berbasis console dan ada yang berbasis Windows Form, yang berbasis console codingannya gak jauh - jauh beda lah sama C++, maka dari itu ane pilih memposting C# yang berbasis Form aja, dan psostingan pertama C# Windows Form ane akan membahas tentang Program Send Mail Google. Dalam codingnya kita akan menggunakan SMTP dari google, yaitu "smtp.gmail.com". Nanti setelah Program dijalankan, akan ada pengecekan terhadap email yang kita gunakan untuk mengirim email, apakah email yang kita gunakan itu valid atau tidak.
  1. Silahkan Buat desain Formnya terlebih dahulu
    Spoiler:

    Disini menggunakn 6 textbox, 2 Button, 6 Label, dan 3 GroupBox, 1 Tools OpenFileDialog. Ubah Name TextBox pertama menjadi textBoxfrom TextBox kedua menjadi textBoxpass TextBox ketiga menjadi textBoxto TextBox keempat menjadi textBoxsub TextBox kelima menjadi textBoxBody TextBox keenam menjadi textBox1 Ubah name label Change User menjadi CU dan Set visible label'a menjadi False
  2. Klik Kanan pada form --> View Code, kemudian tambahkan sebuah library mail
    using System.Net.Mail;
  3. Klik 2 kali label Change User, kemudian tambahkan code berikut
    textBoxfrom.Enabled = true;
    textBoxpass.Enabled = true;
    textBoxfrom.Text = "";
    textBoxpass.Text = "";
    CU.Visible = false;
  4. Klik 2 kali pada button Browse, kemudian tambahkan code berikut
    DialogResult result = openFileDialog1.ShowDialog();
    if (result == DialogResult.OK)
    {
           string file = openFileDialog1.FileName;
           textBox1.Text = file;
    }
  5. Klik 2 kali pada button Send Mail, kemudian isi code berikut
    Spoiler:
    try
                {
                    if (textBoxto.Text == "" || textBoxsub.Text == "" || textBoxBody.Text == "")
                    {
                        MessageBox.Show("Periksa Kolom Dengan Benar", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    else if (textBox1.Text == "")
                    {
                        MailMessage mail = new MailMessage();
                        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                        mail.From = new MailAddress(textBoxfrom.Text);
                        mail.To.Add(textBoxto.Text);
                        mail.Subject = textBoxsub.Text;
                        mail.Body = textBoxBody.Text;
                        SmtpServer.Port = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential(textBoxfrom.Text, textBoxpass.Text);
                        SmtpServer.EnableSsl = true;
                        SmtpServer.Send(mail);
                        MessageBox.Show("Mail Send", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textBoxfrom.Enabled = false;
                        textBoxpass.Enabled = false;
                        textBoxto.Text = "";
                        textBoxsub.Text = "";
                        textBoxBody.Text = "";
                        CU.Visible = true;
                    }

                    else
                    {
                        MailMessage mail = new MailMessage();
                        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                        mail.From = new MailAddress(textBoxfrom.Text);
                        mail.To.Add(textBoxto.Text);
                        mail.Subject = textBoxsub.Text;
                        mail.Body = textBoxBody.Text;
                        Attachment attachment;
                        attachment = new Attachment(textBox1.Text);
                        mail.Attachments.Add(attachment);
                        SmtpServer.Port = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential(textBoxfrom.Text, textBoxpass.Text);
                        SmtpServer.EnableSsl = true;
                        SmtpServer.Send(mail);
                        MessageBox.Show("Mail Send", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textBoxfrom.Enabled = false;
                        textBoxpass.Enabled = false;
                        textBoxto.Text = "";
                        textBoxsub.Text = "";
                        textBoxBody.Text = "";
                        textBox1.Text = "";
                        CU.Visible = true;
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Silahkan Periksa Email atau Password Anda","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                }

Dan ini codingan keseluruhannya jika digabung
Spoiler:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

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

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;
                textBox1.Text = file;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBoxto.Text == "" || textBoxsub.Text == "" || textBoxBody.Text == "")
                {
                    MessageBox.Show("Periksa Kolom Dengan Benar", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                else if (textBox1.Text == "")
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress(textBoxfrom.Text);
                    mail.To.Add(textBoxto.Text);
                    mail.Subject = textBoxsub.Text;
                    mail.Body = textBoxBody.Text;
                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential(textBoxfrom.Text, textBoxpass.Text);
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
                    MessageBox.Show("Mail Send", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBoxfrom.Enabled = false;
                    textBoxpass.Enabled = false;
                    textBoxto.Text = "";
                    textBoxsub.Text = "";
                    textBoxBody.Text = "";
                    CU.Visible = true;
                }

                else
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress(textBoxfrom.Text);
                    mail.To.Add(textBoxto.Text);
                    mail.Subject = textBoxsub.Text;
                    mail.Body = textBoxBody.Text;
                    Attachment attachment;
                    attachment = new Attachment(textBox1.Text);
                    mail.Attachments.Add(attachment);
                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential(textBoxfrom.Text, textBoxpass.Text);
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
                    MessageBox.Show("Mail Send", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBoxfrom.Enabled = false;
                    textBoxpass.Enabled = false;
                    textBoxto.Text = "";
                    textBoxsub.Text = "";
                    textBoxBody.Text = "";
                    textBox1.Text = "";
                    CU.Visible = true;
                }
            }

            catch (Exception)
            {
                MessageBox.Show("Silahkan Periksa Email atau Password Anda","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        private void CU_Click(object sender, EventArgs e)
        {
            textBoxfrom.Enabled = true;
            textBoxpass.Enabled = true;
            textBoxfrom.Text = "";
            textBoxpass.Text = "";
            CU.Visible = false;
        }
    }
}
Dan Ini SS'a gan
Spoiler:




Semoga Bermnafaat :)

Read this | Baca yang ini



Widget by [ Free Widget ]

3 comments:

telcan mengatakan...

Now days Business PBX come packed with a lot of features. You can basically customize your business PBX to fit your business needs. When you see the features, you will know how your current phone system is not good enough. I have been using hosted pbx from Telcan. With this business PBX, I can customize the welcome greeting, route calls to multiple numbers, even program what phone number to call at what time, have a professional voicemail, get my voicemail emailed and the list goes on. It is very easy to set up using wizard. Check out PBX

sherlina mengatakan...

www.indobet77.com

Master Agen Bola , Casino , Tangkas , Togel Terbesar
dan Terpercaya Pilihan Para Bettor

Promo Terbaru :
- Bonus  10% New Member Sportsbook
- Bonus 5% New Member Casino Online
- Bonus 10% Setiap Hari Bola Tangkas
- CASHBACK untuk Member
- BONUS REFERRAL 5% + 1% Seumur Hidup

untuk Informasi lebih jelasnya silahkan hubungi CS kami :
- YM : indobet77_sb2@yahoo.com
- EMAIL : indobet77@gmail.com
- WHATSAPP : +63 905 213 7238
- WECHAT : indobet77
- SMS CENTER : +63 905 213 7238
- PIN BB : 2B65A547 / 24CC5D0F

Salam Admin ,
http://indobet77.com/

sherlina halim mengatakan...

Pengen yang lebih seru ...
Ayo kunjungi www.asianbet77.com
Buktikan sendiri ..

Real Play = Real Money

- Bonus Promo Red Card pertandingan manapun .
- Bonus Mixparlay .
- Bonus Tangkasnet setiap hari .
- New Produk Sabung Ayam ( minimal bet sangat ringan ) .
- Referal 5 + 1 % ( seumur hidup ) .
- Cash Back up to 10 % .
- Bonus Royalty Rewards setiap bulan .

Untuk Informasi lebih jelasnya silahkan hubungi CS kami :
- YM : op1_asianbet77@yahoo.com
- EMAIL : melasian77cs@gmail.com
- WHATSAPP : +63 905 213 7234
- WECHAT : asianbet_77
- SMS CENTER : +63 905 209 8162
- PIN BB : 2B4BB06A / 28339A41

Salam Admin ,
asianbet77.com

Download Disini

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Cheap Web Hosting