· 8 years ago · May 27, 2018, 05:12 AM
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.IO;
11using System.Web;
12using System.Security.Cryptography;
13using System.Net.Mail;
14
15namespace Tienda_Virtual
16{
17 class SendEmail
18 {
19 private string smtp = "", correoFrom = "", contra = "", _correoTo, _body, _subject;
20
21 public string subject
22 {
23 get { return _subject; }
24 set { _subject = value; }
25 }
26 private bool _enviado;
27
28 public bool enviado
29 {
30 get { return _enviado; }
31 set { _enviado = value; }
32 }
33
34 public string body
35 {
36 get { return _body; }
37 set { _body = value; }
38 }
39
40 public string correoTo
41 {
42 get { return _correoTo; }
43 set { _correoTo = value; }
44 }
45
46 public void CreateEmail()
47 {
48 string[] split = _correoTo.Split(new char[] { '@' });
49 if (split[1] == "gmail.com" || split[1] == "ucol.mx")
50 {
51 smtp = "smtp.gmail.com";
52 correoFrom = "barbosa_gonzalez@ucol.mx";
53 contra = "edsel94";
54 }
55 else if (split[1] == "outlook.com" || split[1] == "hotmail.com" || split[1] == "live.com")
56 {
57 smtp = "smtp.live.com";
58 correoFrom = "torby@outlook.com";
59 contra = "e.-94B:_41";
60 }
61 MailMessage mail = new MailMessage();
62 mail.From = new MailAddress("torby@outlook.com");
63 mail.To.Add(_correoTo);
64 mail.Subject = _subject;
65 mail.IsBodyHtml = true;
66 mail.Body = _body;
67 SmtpClient SmtpServer = new SmtpClient(smtp);
68 SmtpServer.Port = 587;
69 SmtpServer.UseDefaultCredentials = false;
70 SmtpServer.Credentials = new System.Net.NetworkCredential(correoFrom, contra);
71 SmtpServer.EnableSsl = true;
72 SmtpServer.Send(mail);
73 _enviado = true;
74 }
75 }
76}