var application = new Application(); var mail = (_MailItem) application.CreateItem(OlItemType.olMailItem); mail.To = "anonymous@somedomain.com"; .... Outlook.Account account = Application.Session.Accounts["MyOtherAccount"]; mailItem.SendUsingAccount = account; mail.Send();
public ActionResult dailyLog(String email) { email = Request.QueryString["email"]; try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = "Hello, Jawed your message body will go here!!"; //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 = "Your Subject will go here."; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email); oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; return View(); }//end of try block catch (Exception ex) { return View(); }//end of catch
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)