Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("### E-mail sender gmail ###");

            GEmail gmail = new GEmail();

            Console.WriteLine("Enter Sender Email");
            gmail.SenderEmail = new MailAddress(Console.ReadLine());
            Console.WriteLine("Enter Recipient Email");
            gmail.RecipientEmail = new MailAddress(Console.ReadLine());
            Console.WriteLine("Enter Subject");
            gmail.Subject = Console.ReadLine();
            //Console.WriteLine("Enter email message");
            gmail.Message = "<h1>Hello World 2.</h1><br /><img src='http://localhost:56078/Handler1.ashx?id=1' />";
            Console.WriteLine("Enter gmail id");
            gmail.GmailId = Console.ReadLine();
            Console.WriteLine("Enter password");
            gmail.GmailPwd = Console.ReadLine();

            try
            {
                GEmail.SendMessage(gmail);
                Console.WriteLine("Mail send");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occured " + ex.Message);
                Console.ReadLine();
            }
        }
Exemple #2
0
        public static void SendMessage(GEmail gm)
        {
            MailMessage gmail  = new MailMessage(gm.SenderEmail, gm.RecipientEmail);
            SmtpClient  client = new SmtpClient();

            client.Port                  = 25;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential(gm.GmailId, gm.GmailPwd);

            client.Host      = "smtp.gmail.com";
            client.EnableSsl = true;
            gmail.Subject    = gm.Subject;
            gmail.Body       = gm.Message;
            gmail.IsBodyHtml = true;
            client.Send(gmail);
        }