public bool SendMail(DbEmail email) { Outlook.Attachment oAttach; try { // Create the Outlook application by using inline initialization. Outlook.Application oApp = new Outlook.Application(); //Create the new message by using the simplest approach. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); //Add a recipient Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(email.Recipient); oRecip.Resolve(); //Set the basic properties. oMsg.Subject = email.Subject; oMsg.Body = email.Body; //Add an attachment //if (email.Attachments.Count > 0) //{ // for (int i = 0; i < email.Attachments.Count(); i++) // { // String sSource = email.Attachments[i]; // String sDisplayName = email.Subject; // int iPosition = (int)oMsg.Body.Length + 1; // int iAttachType = (int)Outlook.OlAttachmentType.olByValue; // oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName); // } //} // If you want to, display the message. // oMsg.Display(true); //modal //Send the message. oMsg.Save(); //(oMsg as _Outlook.MailItem).Send(); //Outlook.Account account = oApp.Session.Accounts[email.Sender]; //oMsg.SendUsingAccount = account; ((Outlook._MailItem)oMsg).Send(); //Explicitly release objects. oRecip = null; oAttach = null; oMsg = null; oApp = null; return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); //Label1.Text = ex.Message + ex.StackTrace; return(false); } }
public bool SendMail(DbEmail email) { Outlook.Attachment oAttach; try { // Create the Outlook application by using inline initialization. Outlook.Application oApp = new Outlook.Application(); //Create the new message by using the simplest approach. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); //Add a recipient Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(email.Recipient); oRecip.Resolve(); //Set the basic properties. oMsg.Subject = email.Subject; oMsg.Body = email.Body; //Add an attachment //if (email.Attachments.Count > 0) //{ // for (int i = 0; i < email.Attachments.Count(); i++) // { // String sSource = email.Attachments[i]; // String sDisplayName = email.Subject; // int iPosition = (int)oMsg.Body.Length + 1; // int iAttachType = (int)Outlook.OlAttachmentType.olByValue; // oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName); // } //} // If you want to, display the message. // oMsg.Display(true); //modal //Send the message. oMsg.Save(); //(oMsg as _Outlook.MailItem).Send(); //Outlook.Account account = oApp.Session.Accounts[email.Sender]; //oMsg.SendUsingAccount = account; ((Outlook._MailItem)oMsg).Send(); //Explicitly release objects. oRecip = null; oAttach = null; oMsg = null; oApp = null; return true; } catch (Exception ex) { Console.WriteLine(ex.Message); //Label1.Text = ex.Message + ex.StackTrace; return false; } }
public void TestSendMailSendsAnEmail() { DbEmail testMail = new DbEmail(); testMail.Sender = "*****@*****.**"; testMail.Recipient = "*****@*****.**"; testMail.Subject = "hi hinnah"; testMail.Body = "test"; SendComInteropEmail email = new SendComInteropEmail(); Assert.IsTrue(email.SendMail(testMail)); }
public bool Execute(Guid sessionID, string recipientEmail) { try { // Get userEmail string qry = "SELECT email FROM FDMUSER JOIN SESSIONS ON FDMUSER.user_id = SESSIONS.user_id WHERE session_guid = '" + sessionID.ToString() + "'"; ReadOneCommand cmd = new ReadOneCommand(); string userEmail = cmd.Execute(qry); DbEmail email = new DbEmail(); email.Sender = userEmail; email.Recipient = recipientEmail; return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public bool Execute(Guid sessionID, string recipientEmail) { try { // Get userEmail string qry = "SELECT email FROM FDMUSER JOIN SESSIONS ON FDMUSER.user_id = SESSIONS.user_id WHERE session_guid = '" + sessionID.ToString() + "'"; ReadOneCommand cmd = new ReadOneCommand(); string userEmail = cmd.Execute(qry); DbEmail email = new DbEmail(); email.Sender = userEmail; email.Recipient = recipientEmail; return true; } catch (Exception e) { Console.WriteLine(e.Message); return false; } }
public bool EmailPassword(string username) { try { DbEmail mail = new DbEmail(); mail.Sender = "*****@*****.**"; mail.Recipient = username + "@fdmgroup.com"; mail.Subject = " your password"; mail.Body = "Dear " + username + "! Your password is : " + Read(username) + " Thank you!"; SendComInteropEmail sendMail = new SendComInteropEmail(); sendMail.SendMail(mail); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
public bool EmailPassword(string username) { try { DbEmail mail = new DbEmail(); mail.Sender = "*****@*****.**"; mail.Recipient = username + "@fdmgroup.com"; mail.Subject = " your password"; mail.Body = "Dear " + username + "! Your password is : " +Read(username) + " Thank you!"; SendComInteropEmail sendMail = new SendComInteropEmail(); sendMail.SendMail(mail); return true; } catch (Exception ex) { Console.WriteLine(ex.Message); } return false; }
public bool SendUserEmail(DbEmail email) { ISendEmail mail = new SendComInteropEmail(); return mail.SendMail(email); }