Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Mail;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace poslaniemalu
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.         //    try
  16.         //    {
  17.         //        MailMessage m = new MailMessage("martin.bielik10@mail.com", "martin.bielik10@mail.com");
  18.         //        m.Subject = "nothing";
  19.         //        m.Body = "nothing";
  20.         //        m.IsBodyHtml = true;
  21.         //        m.From = new MailAddress("martin.bielik10@mail.com");
  22.  
  23.         //        m.To.Add(new MailAddress("martin.bielik10@mail.com"));
  24.         //        SmtpClient smtp = new SmtpClient();
  25.         //        smtp.Port = 25;
  26.         //        smtp.Host = "Gate33.gw.tietoenator.com";
  27.  
  28.         //        NetworkCredential authinfo = new NetworkCredential("martin.bielik10@mail.com", "moje heslo");
  29.         //        smtp.UseDefaultCredentials = false;
  30.         //        smtp.Credentials = authinfo;
  31.         //        smtp.Send(m);
  32.         //    }
  33.         //    catch (Exception ex)
  34.         //    {
  35.         //        Console.WriteLine(ex.ToString());
  36.  
  37.         //    }
  38.             SendMail("martin.bielik10@gmail.com", "martin.bielik10@gmail.com",null,"tralala","nothing");
  39.             Console.ReadKey();
  40.  
  41.         }
  42.         public static string SendMail(string toList, string from, string ccList, string subject, string body)
  43.         {
  44.  
  45.             MailMessage message = new MailMessage();
  46.             SmtpClient smtpClient = new SmtpClient();
  47.             string msg = string.Empty;
  48.             try
  49.             {
  50.                 MailAddress fromAddress = new MailAddress(from);
  51.                 message.From = fromAddress;
  52.                 message.To.Add(toList);
  53.                 if (ccList != null && ccList != string.Empty)
  54.                     message.CC.Add(ccList);
  55.                 message.Subject = subject;
  56.                 message.IsBodyHtml = true;
  57.                 message.Body = body;
  58.                 smtpClient.Host = "Gate33.gw.tietoenator.com";   // We use gmail as our smtp client
  59.                 smtpClient.Port = 25;
  60.                 //smtpClient.EnableSsl = true;
  61.                 //smtpClient.UseDefaultCredentials = true;
  62.                 //smtpClient.Credentials = new System.Net.NetworkCredential("martin.bielik10@gmail.com", "moje heslo");
  63.  
  64.                 smtpClient.Send(message);
  65.                 msg = "Successful<BR>";
  66.             }
  67.             catch (Exception ex)
  68.             {
  69.                 msg = ex.Message;
  70.             }
  71.             return msg;
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement