Advertisement
700hours

smtp

Oct 7th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. // references: http://www.kbcafe.com/articles/HowTo.SMTP.CSharp.pdf
  2. // http://stackoverflow.com/questions/5899180/sending-an-email-through-gmail-smtp-server-ssl
  3.  
  4. using System;
  5. using System.IO;
  6. using System.Net;
  7. using System.Net.Mail;
  8.  
  9. namespace smtprush
  10. {
  11.     public class Core
  12.     {
  13.         private static string
  14.             txtpath = "",
  15.             body;
  16.         public static void Main(string[] args)
  17.         {
  18.             for (int i = 0; i < args.Length; i++)
  19.             {
  20.                 if(args[i] == "-txt")
  21.                 {
  22.                     txtpath = args[++i];
  23.                     Text();
  24.                 }
  25.             }
  26.             try
  27.             {
  28.                 SmtpClient smtp = new SmtpClient
  29.                 {
  30.                     Host = args[0],
  31.                     Port = Convert.ToInt32(args[1]),
  32.                     EnableSsl = true,
  33.                     DeliveryMethod = SmtpDeliveryMethod.Network,
  34.                     UseDefaultCredentials = false,
  35.                     Credentials = new NetworkCredential(args[2], args[3]),
  36.                     Timeout = 10000
  37.                 };
  38.                 MailMessage message = new MailMessage(args[4], args[5], args[6], body);
  39.                 message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  40.  
  41.                 smtp.Send(message);
  42.             }
  43.             catch (Exception ex)
  44.             {
  45.                 Console.WriteLine("{0} Exception caught.", ex);
  46.             }
  47.             Console.WriteLine("Host " + args[0]);
  48.             Console.WriteLine("Port " + args[1]);
  49.             Console.WriteLine("Username " + args[2]);
  50.             Console.WriteLine("Password " + args[3]);
  51.             Console.WriteLine("From " + args[4]);
  52.             Console.WriteLine("To " + args[5]);
  53.             Console.WriteLine("Subject " + args[6]);
  54.             Console.WriteLine("Body " + body);
  55.         }
  56.         private static string Text()
  57.         {
  58.             using (StreamReader sr = new StreamReader(txtpath))
  59.             {
  60.                 string[] lines = sr.ReadToEnd().Split(';');
  61.                 for (int i = 0; i < lines.Length; i++)
  62.                 {
  63.                     body += lines[i];
  64.                 }
  65.             }
  66.             return body;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement