using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace GroundZero.KeyCodes { public partial class ALResponse : Form { private Chilkat.Email em=null; bool bLite = false; bool _xmlMode = true; public ALResponse(Chilkat.Email ALRequestEmail, bool XMLMode) { InitializeComponent(); _xmlMode = XMLMode; if (ALRequestEmail == null) { MessageBox.Show("No request email found - tell Johnny"); this.Close(); return; } em = ALRequestEmail; string s = ""; if (!string.IsNullOrWhiteSpace(em.GetPlainTextBody())) s = em.GetPlainTextBody(); else s = em.Body; edRequest.Text = s; sendToolStripMenuItem.Text = "&Send to " + em.FromAddress; Generate(_xmlMode); } private void sendToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Send both response emails to customer now?", "Email now", MessageBoxButtons.YesNo) != DialogResult.Yes) return; //smtp send responses string sEmailTo = em.FromAddress; if (string.IsNullOrWhiteSpace(sEmailTo)) { MessageBox.Show("Error, the return email address is empty, no one to reply to!"); return; } //Send the greeting message first string sLastError=SendMessage(sEmailTo, "re: " + em.Subject, edGreeting.Text, ""); if ( sLastError != null) { MessageBox.Show("Error sending greeting message:\r\n" + sLastError); return; } string sKeyEmailSubject = ""; if (bLite) sKeyEmailSubject = "AyaNova Lite and optional add-ons temporary 30 day Activation key"; else sKeyEmailSubject = "AyaNova and optional add-on's temporary 30 day Activation key"; sLastError = SendMessage(sEmailTo, sKeyEmailSubject,this.edKeyCode.Text, ""); if (sLastError != null) { MessageBox.Show("Error sending keycode message:\r\n" + sLastError); return; } this.DialogResult = System.Windows.Forms.DialogResult.Yes; this.Close(); } /// /// Send a message with optional attachment /// /// /// /// /// /// null on success otherwise the error message private string SendMessage(string sTo, string sSubject, string sBody, string sAttach) { //attempt delivery // Create a mailman object for sending email. Chilkat.MailMan mailman = new Chilkat.MailMan(); mailman.UnlockComponent("SAyanovaMAILQ_46WCmUg3lQ1i"); // Set the SMTP server hostname. mailman.SmtpHost = "smtp.ayanova.com"; //Case 515 //mailman.SmtpPort = 587; //SSL case 1973 mailman.SmtpSsl = true; mailman.SmtpPort = 465; mailman.SmtpUsername = "support@ayanova.com"; mailman.SmtpPassword = "RLdUP6758a6191H"; // Create a simple email. Chilkat.Email email = new Chilkat.Email(); email.Body = sBody; email.Subject = sSubject; email.AddTo("", sTo); email.From = "support@ayanova.com"; // Send mail. bool success; success = mailman.SendEmail(email); if (success) { CopyToSentFolder(email); return null; } else { return mailman.LastErrorText; } } public static void CopyToSentFolder(Chilkat.Email em) { Chilkat.Imap imap = new Chilkat.Imap(); bool success; success = imap.UnlockComponent("SAyanovaIMAPMAIL_Es9JHNMSlUlb"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } //Use SSL case 1973 imap.Ssl = true; imap.Port = 993; success = imap.Connect("mail.ayanova.com"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } // Login success = imap.Login("support@ayanova.com", "RLdUP6758a6191H"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } //put in sent mail folder success = imap.AppendMail("Sent", em); if (success != true) { MessageBox.Show("Error copying to sent folder: \r\n"+imap.LastErrorText); return; } imap.Logout(); imap.Disconnect(); } private void cancelToolStripMenuItem_Click(object sender, EventArgs e) { this.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.Close(); } void Generate(bool XMLFormat) { string s= edRequest.Text; //make keycode bLite = em.Subject.Contains("AyaNova Lite"); int nNameStart = s.IndexOf("Name:\r\n")+7; int nNameEnd = s.IndexOf("Company:\r\n"); int nCompanyStart = nNameEnd + 10; int nCompanyEnd = s.IndexOf("Referrer:\r\n"); string sName = s.Substring(nNameStart, nNameEnd - nNameStart).Trim(); if (sName.Contains(" ")) sName=sName.Split(' ')[0]; string sRegTo = s.Substring(nCompanyStart, nCompanyEnd - nCompanyStart).Trim(); edKeyCode.Text = MsgGen.TrialKeyMessage(bLite, sRegTo, XMLFormat); //Latest format: //Name: //Joyce //Company: //Ground Zero //Additional: //- //Requested from: //96.54.96.232 //Original format: //Name: //Emin PEKEL //Company: //ECSTURKEY //Postal address: //1370 SOK. NO: 7 KONAK / CANKAYA - IZMIR (TURKEY) //Other: //- //Requested from: //88.247.204.81 //make greeting message edGreeting.Text = MsgGen.TrialGreetingMessage(bLite, sName); edGreeting.Text = edGreeting.Text + "\r\n\r\nOn " + em.LocalDate + ", " + em.From + " wrote:\r\n" + edRequest.Text.Replace("\r\n","\r\n>"); } private void regenerateMessagesToolStripMenuItem_Click(object sender, EventArgs e) { edKeyCode.Text = ""; edGreeting.Text = ""; Generate(_xmlMode); } } }