-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultWriter.aspx.cs
113 lines (106 loc) · 3.33 KB
/
DefaultWriter.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DefaultWriter : Page
{
MistikaDBDataContext db = new MistikaDBDataContext();
protected void Page_Load(object sender, EventArgs e)
{
CreateText();
//SendMailsMails("","");
}
public void SendMails(string mailaddress, string password, List<string> listmails, bool clearAll)
{
try
{
MailMessage mail = new MailMessage();
NetworkCredential cred = new NetworkCredential(mailaddress, password);
mail.Subject = "";
for (int i = 1; i < listmails.Count(); i++)
{
mail.To.Add(listmails[i]);
}
mail.From = new MailAddress(mailaddress);
mail.IsBodyHtml = true;
mail.Body = File.ReadAllText(HttpContext.Current.Server.MapPath("MiniMail.html"), Encoding.UTF8);
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.Send(mail);
if (clearAll)
{
StreamWriter writer = new StreamWriter(@"C:\Users\Or\Desktop\Spider\TextFile.txt");
writer.WriteLine("");
writer.Close();
}
//Thread.Sleep(25000);
}
catch (Exception gh)
{
string cv = gh.Message;
}
}
public void CreateText()
{
StreamWriter writer = new StreamWriter(@"C:\Users\Or\Desktop\Spider\TextFile.txt");
var mails = from m in db.CVMails
where m.MailSent == null || m.MailSent == false
select m;
StringBuilder builder = new StringBuilder();
foreach (var s in mails)
{
builder.Append(s.MailValue + ",");
s.MailSent = true;
db.SubmitChanges();
}
writer.Write(builder.ToString());
writer.Close();
}
public void SendMailsMails(string mail, string password)
{
StreamReader reader = new StreamReader(@"C:\Users\Or\Desktop\Spider\TextFile.txt");
string ssdf = reader.ReadToEnd();
reader.Close();
string[] listmails = ssdf.Split(',');
List<string> lista = new List<string>();
string last = string.Empty;
if (listmails.Count() > 500)
{
last = listmails[489];
for (int i = 0; i < 490; i++)
{
lista.Add(listmails[i]);
}
}
else
{
for (int i = 0; i < listmails.Count(); i++)
{
lista.Add(listmails[i]);
}
}
if (!string.IsNullOrEmpty(last))
{
StreamWriter r = new StreamWriter(@"C:\Users\Or\Desktop\Spider\LastMail.txt");
r.WriteLine(last);
r.Close();
}
else
{
StreamWriter r = new StreamWriter(@"C:\Users\Or\Desktop\Spider\LastMail.txt");
r.WriteLine("");
r.Close();
}
SendMails(mail, password, lista, false);
}
}