public static void CheckForNewLettersIMAP(Profile user, int letterNum) { Letter newLetter = new Letter(); newLetter.To = user.Adress; Authenticate(user); ImapRequest("$ SELECT INBOX\r\n"); ImapRequest("$ STATUS INBOX (MESSAGES)\r\n"); List<string> letterHeader = GetHeaderOfLetter(letterNum); foreach (string line in letterHeader) { if (line.Contains("From: ")) { newLetter.From = line.Substring(6); MessageBox.Show(line.Substring(6)); } if (line.Contains("Date: ")) { MessageBox.Show(line.Substring(6)); } if (line.Contains("Subject: ")) { newLetter.Subject = line.Substring(9); MessageBox.Show(line.Substring(9)); } } Authenticate(user); ImapRequest("$ SELECT INBOX\r\n"); newLetter.Body = GetTextOfLetter(letterNum); }
public void SendLetterSMTP(Profile sender, Letter letter) { SmtpClient smtp = new SmtpClient("smtp." + sender.Server, sender.SmtpPort); smtp.Credentials = new System.Net.NetworkCredential(sender.Adress, sender.Password); MailMessage message = new MailMessage(); message.From = new MailAddress(sender.Adress); message.To.Add(new MailAddress(letter.To)); message.Subject = letter.Subject; message.Body = letter.Body; smtp.EnableSsl = true; foreach (ExtendedAttachment attachmentExt in lbAttachments.Items) { message.Attachments.Add(attachmentExt.AttachedObject); } smtp.Send(message); }
private void btSend_Click(object sender, RoutedEventArgs e) { MainWindow main = this.Owner as MainWindow; if (tbAdress.Text != string.Empty && tbMessage.Text != string.Empty && tbSubject.Text != string.Empty) { string adressesText = tbAdress.Text.Replace(" ", string.Empty); string[] recievers = adressesText.Split(','); foreach (string reciever in recievers) { Letter letter = new Letter(this.mailSender.Id, tbSubject.Text, tbMessage.Text, this.mailSender.Adress, tbAdress.Text, "Outbox", DateTime.Now); letter.SetId(); this.SendLetterSMTP(this.mailSender, letter); Letter.AddLetterToDB(this.mailSender, letter); } this.Close(); main.FillProfilesListFull(); } }
public Letter GetLetter() { Letter letter = new Letter(); LocalSQLConnection sqlconnectionClass = new LocalSQLConnection(); SqlCommand cmd = sqlconnectionClass.DeployConnectionAndCommand(); cmd.CommandText = "select * from Mail where Id='" + this.Id + "'"; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { letter = new Letter(dr); } } sqlconnectionClass.CloseConnection(); return letter; }
public LetterPreparator(Letter letterItem) : base(letterItem) { }
public Letter CheckLetterByIMAP(Profile user, int letterNum) { Letter newLetter = new Letter(); newLetter.SetId(); newLetter.ProfileId = user.Id; newLetter.To = user.Adress; newLetter.Category = "Inbox"; bool subjectFound = false; bool dateFound = false; bool fromFound = false; ImapConsole console = new ImapConsole(); console.SetSSLConnection(user); console.SendCommand(new ImapAuthenticate(user)); console.ExecuteCommand(); this.ImapRequest("$ SELECT INBOX\r\n"); console.SendCommand(new ImapGetHeaderOfLetter(letterNum)); List<string> letterHeader = (List<string>)console.ExecuteCommand(); foreach (string line in letterHeader) { if (!fromFound && line.Contains("From: ")) { string thisLine = line; if (line.Contains("<")) { thisLine = line.Substring(line.IndexOf('<') + 1, line.IndexOf('>') - line.IndexOf('<') - 1); newLetter.From = thisLine; } else { newLetter.From = thisLine.Substring(6); } fromFound = true; } if (!dateFound && line.Length > 6 && line.Substring(0, 6) == "Date: ") { string thisLine = line; if (line.Contains("+")) { thisLine = line.Substring(0, line.IndexOf('+')); } else if (line.Contains("-")) { thisLine = line.Substring(0, line.IndexOf('-')); } newLetter.SendingTime = Convert.ToDateTime(thisLine.Substring(6)); dateFound = true; } if (!subjectFound && line.Contains("Subject: ")) { newLetter.Subject = line.Substring(9).Replace("\r", string.Empty); if (newLetter.Subject.Substring(0, 5) == "=?utf") { newLetter.Subject = newLetter.Subject.Substring(10, newLetter.Subject.Length - 10); interpreterContext iC = new interpreterContext(newLetter.Subject); DefaultExpression ex = new DefaultExpression(); ex.Interpret(iC); newLetter.Subject = ex.UseEncoding(iC); } subjectFound = true; } if (subjectFound && dateFound && fromFound) { break; } } console.SetSSLConnection(user); console.SendCommand(new ImapAuthenticate(user)); console.ExecuteCommand(); this.ImapRequest("$ SELECT INBOX\r\n"); console.SendCommand(new ImapGetTextOfLetter(letterNum)); newLetter.Body = (string)console.ExecuteCommand(); return newLetter; }
public static void AddLetterToDB(Profile user, Letter letter) { LocalSQLConnection sqlconnectionClass = new LocalSQLConnection(); SqlCommand cmd = sqlconnectionClass.DeployConnectionAndCommand(); cmd.CommandText = "insert into Mail (Id, ProfileId, Subject,Body, AdressFrom, AdressTo, Category, Time)" + " values (@id, @pid, @s, @b, @af, @at, @c, @t)"; letter.SetId(); cmd.Parameters.AddWithValue("@id", letter.Id); cmd.Parameters.AddWithValue("@pid", user.Id); cmd.Parameters.AddWithValue("@s", letter.Subject); cmd.Parameters.AddWithValue("@b", letter.Body); cmd.Parameters.AddWithValue("@af", letter.From); cmd.Parameters.AddWithValue("@at", letter.To); cmd.Parameters.AddWithValue("@c", letter.Category); cmd.Parameters.AddWithValue("@t", letter.SendingTime); cmd.ExecuteNonQuery(); sqlconnectionClass.CloseConnection(); }