Guest User

Untitled

a guest
Aug 14th, 2017
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net.Mail;
  9.  
  10. namespace Hesla2
  11. {
  12. public partial class Form1 : Form
  13. {
  14.  
  15. public SmtpClient client = new SmtpClient();
  16. public MailMessage msg = new MailMessage();
  17.  
  18. public System.Net.NetworkCredential smtpCreds = new System.Net.NetworkCredential("[email protected]", "heslo_ti_rikat_nebudu_:D");
  19.  
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. public void SendEmail(string sendTo, string sendFrom, string subject, string body)
  26. {
  27. try
  28. {
  29. client.Host = "smtp.gmail.com";
  30. client.Port = 587;
  31. client.UseDefaultCredentials = false;
  32. client.Credentials = smtpCreds;
  33. client.EnableSsl = true;
  34.  
  35. MailAddress to = new MailAddress(sendTo);
  36. MailAddress from = new MailAddress(sendFrom);
  37.  
  38. msg.Subject = subject;
  39. msg.Body = body;
  40. msg.From = from;
  41. msg.To.Add(to);
  42.  
  43. client.Send(msg);
  44. }
  45. catch(Exception ex)
  46. {
  47. MessageBox.Show(ex.Message, "ERROR");
  48. }
  49. }
  50.  
  51. private void button1_Click(object sender, EventArgs e)
  52. {
  53. SendEmail("[email protected]", "[email protected]", textBox1.Text, textBox2.Text);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment