Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MailMessage mail = new MailMessage();
- mail.From = new MailAddress("login@yandex.ru", "Name");
- mail.To.Add(account.Email);
- mail.Subject = "Hello";
- mail.Body = "Hello from Asp.net mvc";
- mail.IsBodyHtml = true;
- SmtpClient client = new SmtpClient();
- client.Host = "smtp.yandex.ru";
- client.Port = 587;
- client.Credentials = new NetworkCredential("login@yandex.ru","password");
- client.Send(mail);
- db.Registration.Add(account);
- db.SaveChanges();
- public static void SendEmail(string email, string text, string subject)
- {
- MailAddress from = new MailAddress("aspnet.confirmation@yandex.ru", "ASP.NET Blog");
- MailAddress to = new MailAddress(email);
- MailMessage message = new MailMessage(from, to);
- message.Subject = subject;
- message.Body = text;
- message.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp.yandex.ru", 25);
- smtp.Credentials = new System.Net.NetworkCredential("aspnet.confirmation@yandex.ru", "yourpassword");
- smtp.EnableSsl = true;
- smtp.Send(message);
- }
- public static void SendEmail(string title, string text, string emailTo, bool isBodyHtml = false)
- {
- try
- {
- MailMessage mail = new MailMessage();
- mail.IsBodyHtml = isBodyHtml;
- mail.From = new MailAddress(ConstantsWeb.Email.Address.RobotEmail, ConstantsWeb.Global.CompanyName);
- mail.To.Add(emailTo);
- mail.Subject = title;
- mail.Body = text;
- mail.SubjectEncoding = Encoding.GetEncoding("utf-8");
- mail.Priority = MailPriority.Normal;
- SmtpClient SmtpServer = new SmtpClient(ConstantsWeb.Email.Server.Name)
- {
- Credentials = new NetworkCredential(ConstantsWeb.Email.Address.RobotEmail, ConstantsWeb.Email.Address.RobotEmailPassword),
- Port = ConstantsWeb.Email.Server.Port,
- EnableSsl = ConstantsWeb.Email.Server.UseSsl
- };
- SmtpServer.Send(mail);
- }
- catch(Exception e)
- {
- //do whatever...
- }
- }
Add Comment
Please, Sign In to add comment