Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // references: http://www.kbcafe.com/articles/HowTo.SMTP.CSharp.pdf
- // http://stackoverflow.com/questions/5899180/sending-an-email-through-gmail-smtp-server-ssl
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Mail;
- namespace smtprush
- {
- public class Core
- {
- private static string
- txtpath = "",
- body;
- public static void Main(string[] args)
- {
- for (int i = 0; i < args.Length; i++)
- {
- if(args[i] == "-txt")
- {
- txtpath = args[++i];
- Text();
- }
- }
- try
- {
- SmtpClient smtp = new SmtpClient
- {
- Host = args[0],
- Port = Convert.ToInt32(args[1]),
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(args[2], args[3]),
- Timeout = 10000
- };
- MailMessage message = new MailMessage(args[4], args[5], args[6], body);
- message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
- smtp.Send(message);
- }
- catch (Exception ex)
- {
- Console.WriteLine("{0} Exception caught.", ex);
- }
- Console.WriteLine("Host " + args[0]);
- Console.WriteLine("Port " + args[1]);
- Console.WriteLine("Username " + args[2]);
- Console.WriteLine("Password " + args[3]);
- Console.WriteLine("From " + args[4]);
- Console.WriteLine("To " + args[5]);
- Console.WriteLine("Subject " + args[6]);
- Console.WriteLine("Body " + body);
- }
- private static string Text()
- {
- using (StreamReader sr = new StreamReader(txtpath))
- {
- string[] lines = sr.ReadToEnd().Split(';');
- for (int i = 0; i < lines.Length; i++)
- {
- body += lines[i];
- }
- }
- return body;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement