Advertisement
stuxjkee

Untitled

May 19th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Net;
  2. using System.Net.Mail;
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6.  
  7. namespace Alarm_ {
  8.     class Mail {
  9.         public static string username = "info.monicam@gmail.com";
  10.         public static string password = "monicampassword";
  11.        
  12.         public static void email_send(List<string> filenames) {
  13.             MailMessage mail = new MailMessage();
  14.             SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  15.             mail.From = new MailAddress("alarma@gmail.com");
  16.             mail.To.Add(Values.email);
  17.             mail.Subject = "Alarm! Was a signal";
  18.             mail.Body = "Possible danger at " + DateTime.Now.ToString("dd MMM HH:mm:ss");
  19.  
  20.             System.Net.Mail.Attachment attachment;
  21.  
  22.             foreach (string filename in filenames) {
  23.                 attachment = new System.Net.Mail.Attachment(filename);
  24.                 mail.Attachments.Add(attachment);
  25.             }
  26.  
  27.             SmtpServer.Port = 587;
  28.             SmtpServer.Credentials = new System.Net.NetworkCredential(username, password);
  29.             SmtpServer.EnableSsl = true;
  30.  
  31.             SmtpServer.Send(mail);
  32.  
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement