public static bool notificaMailDisservizio(SvrPosta svr, string destAddress, string mittAddress, string subject, string body) { CMAttachment[] attachments = null; bool ret = true; try { svr.connect(); svr.sendMail(mittAddress, destAddress, subject, body, attachments); } catch (Exception e) { logger.Error(e.Message); ret = false; svr.disconnect(); } finally { if (svr != null) { svr.disconnect(); } } return(ret); }
/*private static void creaMail(string username,string password,string server,string port,string mailMitt,string mailDest,string numRegMitt,string pathFiles){ * WinToolZone.CSLMail.SMTP smtp=new WinToolZone.CSLMail.SMTP(); * try * { * smtp.Username=username; * smtp.Password=password; * smtp.Authentication=WinToolZone.CSLMail.SMTP.SMTPAuthenticationType.LOGIN; * smtp.From=mailMitt; * smtp.To=mailDest; * smtp.MailType=WinToolZone.CSLMail.SMTP.MailEncodingType.HTML; * smtp.Subject="Conferma ricezione"; * //body della mail * string bodyMail="Conferma di ricezione del messaggio con numero di protocollo "+numRegMitt; * smtp.Message=bodyMail; * smtp.SMTPServer=server; * if(port!=null) * { * smtp.SMTPPort=(short) Int32.Parse(port); * } * string[] files=System.IO.Directory.GetFiles(pathFiles); * for(int i=0;i<files.Length;i++) * { * if(smtp.AddAttachment(files[i])) * { * logger.Debug("Attachment "+files[i]+" inserito"); * } * else * { * logger.Debug("Attachment "+files[i]+"non inserito"); * throw new Exception(); * }; * } * if(!smtp.SendMail()) * { * logger.Debug("Invio mail non eseguito"+smtp.ErrorDescription); * throw new Exception(); * } * } * catch(Exception e) * { * throw e; * } * }*/ #endregion /// <summary> /// /// </summary> /// <param name="server"></param> /// <param name="mailMitt"></param> /// <param name="mailDest"></param> /// <param name="numRegMitt"></param> /// <param name="pathFiles"></param> private static void creaMail(string server, string smtp_user, string smtp_pwd, string mailMitt, string mailDest, string numRegMitt, string pathFiles, string port, string SmtpSsl, string PopSsl, string smtpSTA, string body, string subject) { SvrPosta svr = new SvrPosta(server, smtp_user, smtp_pwd, port, Path.GetTempPath(), CMClientType.SMTP, SmtpSsl, PopSsl, smtpSTA); try { string[] files = System.IO.Directory.GetFiles(pathFiles); List <CMAttachment> attachLst = new List <CMAttachment>(); foreach (string file in files) { CMAttachment att = new CMAttachment(Path.GetFileName(file), Interoperabilità.MimeMapper.GetMimeType(Path.GetExtension(file)), file); attachLst.Add(att); } svr.connect(); svr.sendMail(mailMitt, mailDest, subject, body,//"Conferma di ricezione del messaggio con numero di protocollo " + numRegMitt, attachLst.ToArray()); } catch (Exception e) { logger.Error("Errore nella gestione dell'interoperabilità. (creaMail)", e); throw e; } finally { svr.disconnect(); } }
public static bool notificaByMail(string destAddress, string mittAddress, string subject, string body, string priority, string idAmm, CMAttachment[] attachments) { bool ret = true; System.Data.DataSet ds; SvrPosta svr = null; try { DocsPaDB.Query_Utils.Utils obj = new DocsPaDB.Query_Utils.Utils(); obj.getSmtp(out ds, idAmm); if (ds.Tables["SERVER"].Rows.Count == 0) { ret = false; return(ret); } // string server = ds.Tables["SERVER"].Rows[0]["VAR_SMTP"].ToString(); // string smtp_user = ds.Tables["SERVER"].Rows[0]["VAR_USER_SMTP"].ToString(); // string smtp_pwd = ds.Tables["SERVER"].Rows[0]["VAR_PWD_SMTP"].ToString(); string smtp_user = ""; string smtp_pwd = ""; string server = ds.Tables["SERVER"].Rows[0]["VAR_SMTP"].ToString(); if (!ds.Tables["SERVER"].Rows[0]["VAR_USER_SMTP"].Equals(System.DBNull.Value)) { smtp_user = ds.Tables["SERVER"].Rows[0]["VAR_USER_SMTP"].ToString(); } if (!ds.Tables["SERVER"].Rows[0]["VAR_PWD_SMTP"].Equals(System.DBNull.Value)) { smtp_pwd = DocsPaUtils.Security.Crypter.Decode(ds.Tables["SERVER"].Rows[0]["VAR_PWD_SMTP"].ToString(), smtp_user); } string port = ds.Tables["SERVER"].Rows[0]["NUM_PORTA_SMTP"].ToString(); string SmtpSsl = ds.Tables["SERVER"].Rows[0]["CHA_SMTP_SSL"].ToString(); string SmtpSTA = ds.Tables["SERVER"].Rows[0]["CHA_SMTP_STA"].ToString(); svr = new SvrPosta(server, smtp_user, smtp_pwd, port, Path.GetTempPath(), CMClientType.SMTP, SmtpSsl, "", SmtpSTA); svr.connect(); svr.sendMail(mittAddress, destAddress, subject, body, attachments); } catch (Exception e) { logger.Error(e.Message); ret = false; } finally { if (svr != null) { svr.disconnect(); } } return(ret); }