Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Mail;
- using System.Net;
- namespace GMAIL
- {
- class Program
- {
- static void Main(string[] args)
- {
- var fromAddress = new MailAddress("From Gmail", "From Name");
- var toAddress = new MailAddress("To Address", "To Name");
- const string fromPassword = "Gmail Password";
- const string subject = "Testbesked";
- const string body = "Testbesked";
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- while (Console.ReadLine() != "exit")
- {
- if (Console.ReadLine() == "send")
- {
- using (var message = new MailMessage(fromAddress, toAddress)
- {
- Subject = subject,
- Body = body
- })
- {
- smtp.Send(message);
- Console.WriteLine("Email successfully sent!");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment