Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Hesla2
- {
- public partial class Form1 : Form
- {
- public SmtpClient client = new SmtpClient();
- public MailMessage msg = new MailMessage();
- public System.Net.NetworkCredential smtpCreds = new System.Net.NetworkCredential("[email protected]", "heslo_ti_rikat_nebudu_:D");
- public Form1()
- {
- InitializeComponent();
- }
- public void SendEmail(string sendTo, string sendFrom, string subject, string body)
- {
- try
- {
- client.Host = "smtp.gmail.com";
- client.Port = 587;
- client.UseDefaultCredentials = false;
- client.Credentials = smtpCreds;
- client.EnableSsl = true;
- MailAddress to = new MailAddress(sendTo);
- MailAddress from = new MailAddress(sendFrom);
- msg.Subject = subject;
- msg.Body = body;
- msg.From = from;
- msg.To.Add(to);
- client.Send(msg);
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "ERROR");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SendEmail("[email protected]", "[email protected]", textBox1.Text, textBox2.Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment