<pre lang="c#">using System.Net.Mail; using System.Net; using Outlook = Microsoft.Office.Interop.Outlook; public ActionResult dailyLog(String txtEmailTo, String txtCC, String txtSubject, String txtBody) { if (!String.IsNullOrEmpty(Session["Admin"] as string)) { try { Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMsg.HTMLBody = txtBody; //Add an attachment. //String sDisplayName = "MyAttachment"; int iPosition = (int)oMsg.Body.Length + 1; //int iAttachType = (int)Outlook.OlAttachmentType.olByValue; //now attached the file //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName); //Subject line oMsg.Subject = txtSubject; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(txtEmailTo); oRecip = oRecips.Add(txtCC); oRecip.Type = (int)Outlook.OlMailRecipientType.olCC; oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; ViewBag.Confirmation = "Daily Has Been Log Submitted"; return View(); } catch (Exception ex) { ViewBag.Confirmation = ex.Message; return View(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)