c# - Detect when "Office.Interop.Outlook" don't send mail -
i have c# procedure send mails. procedure call mailitem.send() without error outlook don't send mail, , mail isn't create in outlook "to send" folder.
how detect ?
the code follow:
private void sendmail(string mail, string description) { registrykey key = registry.classesroot; registrykey subkey = key.opensubkey("outlook.application"); if (subkey != null) { if ((process.getprocessesbyname("outlook").length == 0) && (process.getprocessesbyname("outlook.exe").length == 0)) { system.diagnostics.process.start("outlook"); } microsoft.office.interop.outlook.application app = new microsoft.office.interop.outlook.application(); microsoft.office.interop.outlook.mailitem mailitem = app.createitem(microsoft.office.interop.outlook.olitemtype.olmailitem); mailitem.subject = "release notice"; mailitem.to = mail; string bodymessage = description; mailitem.body = bodymessage; mailitem.display(false); mailitem.send(); } else { messagebox.show("impossible send mails. contact system administrator.", "system info", messageboxbuttons.ok, messageboxicon.error); } }
if send()
method not sending error or exception quite possible cannot detect if there error/exception(atleast code)
once message moved outlook server out of reach check status. have rely on outlook server send email.
you can refer article jeff atwood: so you'd send email
Comments
Post a Comment