Advertisement
Guest User

Untitled

a guest
May 16th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Web.Hosting;
  8. using System.Net;
  9. using System.Net.Mail;
  10. using System.Configuration;
  11. using System.IO;
  12. using System.Collections;
  13. //using System.Web.HttpContext.Current.Server;
  14.  
  15. public class htmlsend
  16. {
  17.     //public static string details;
  18.  
  19.     //static void Main(string[] args)
  20.     static void Main()
  21.     {
  22.         string body = string.Empty;
  23.         //using (StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage1.html")))
  24.         //using (StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/mappathtest.html")))
  25.         //using (StreamReader reader = new StreamReader(HostingEnvironment.MapPath("~/mappathtest.html")))
  26.         using (StreamReader reader = new StreamReader(("mappathtest.html")))
  27.         {
  28.             body = reader.ReadToEnd();
  29.  
  30.             string userName = "jack";
  31.             string title = "titlestring";
  32.             string url = "urlstring";
  33.             string description = "descriptionstring";
  34.  
  35.             body = body.Replace("{UserName}", userName);
  36.             body = body.Replace("{Title}", title);
  37.             body = body.Replace("{Url}", url);
  38.             body = body.Replace("{Description}", description);
  39.             //return body;
  40.             //bodystring(body);
  41.             email(body);
  42.         }
  43.     }
  44.  
  45.     /*public static void bodystring(string body)
  46.         {
  47.             Console.WriteLine(body);
  48.         }*/
  49.     public static void email(string body)
  50.     {
  51.         {
  52.             string myemailaddress = "";
  53.             var fromAddress = new MailAddress(myemailaddress, "");
  54.             var toAddress = new MailAddress("", "");
  55.             const string fromPassword = "";
  56.             const string subject = "Subject";
  57.             //string body = globalList.ToString();
  58.             string htmlbody = body;
  59.             /*for (int i = 0; i < globalList.Count; i++)
  60.             {
  61.                 body = body + globalList[i].ToString();
  62.                 Console.WriteLine(globalList[i].ToString());
  63.             }*/
  64.  
  65.  
  66.  
  67.             var smtp = new SmtpClient
  68.             {
  69.                 Host = "smtp.gmail.com",
  70.                 Port = 587,
  71.                 EnableSsl = true,
  72.                 DeliveryMethod = SmtpDeliveryMethod.Network,
  73.                 UseDefaultCredentials = false,
  74.                 Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  75.             };
  76.             using (var message = new MailMessage(fromAddress, toAddress)
  77.             {
  78.                 Subject = subject,
  79.                 Body = htmlbody
  80.             })
  81.             {
  82.                 smtp.Send(message);
  83.                 Console.WriteLine("emailsent");
  84.             }
  85.            
  86.             return;
  87.         }
  88.  
  89.  
  90.  
  91.  
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement