Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.Net.Mail;
  8. using System.IO;
  9.  
  10. namespace EmailBOT
  11. {
  12. class Program
  13. {
  14. static string senderMail = "sveamedia@gmail.com";
  15. static void Main(string[] args)
  16. {
  17. InitializeSmtp();
  18. Profil p1 = new Profil("Alex", "gyros", "alekkenbonken@gmail.com", 01);
  19. MailTemplate.GetTemplate(p1);
  20. SendMail(p1);
  21.  
  22. Console.ReadLine();
  23. }
  24.  
  25. static void SendMail(Profil p1)
  26. {
  27. try
  28. {
  29. Profil.c1.Send(senderMail, p1.email, MailTemplate.title, MailTemplate.body);
  30. Console.WriteLine("email sent");
  31. }
  32. catch
  33. {
  34. Console.WriteLine("email no sent");
  35. }
  36. }
  37.  
  38. static void InitializeSmtp()
  39. {
  40. Profil.c1.EnableSsl = true;
  41. Profil.c1.DeliveryMethod = SmtpDeliveryMethod.Network;
  42. Profil.c1.Credentials = new NetworkCredential("sveamedia@gmail.com", "BIGbucks321");
  43. }
  44. }
  45.  
  46. class Profil
  47. {
  48. public static SmtpClient c1 = new SmtpClient("smtp.gmail.com", 587);
  49. public string namn;
  50. public string alias;
  51. public string email;
  52. public int id;
  53.  
  54. public Profil(string namn, string alias, string email, int id)
  55. {
  56. this.namn = namn;
  57. this.alias = alias;
  58. this.email = email;
  59. this.id = id;
  60. }
  61. }
  62.  
  63. class MailTemplate
  64. {
  65. public static string title = "Partner Rekrytering - Svea Media";
  66. public static string body;
  67. //ändra till en generell
  68.  
  69. public static void GetTemplate(Profil p1)
  70. {
  71. string path = @"C:\Users\alex.fooladi\Desktop\MailTemplate.txt";
  72. body = string.Format(File.ReadAllText(path, Encoding.Default), p1.namn);
  73. }
  74.  
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement