public static void Send() { var mail = new Rebex.Mail.MailMessage { From = "*****@*****.**", To = "*****@*****.**", Subject = "Novo pedido de oração", BodyHtml = "<h1> Hello World</h1>" }; }
/************************************************************ * Function name : SetMailSend * Purpose : Mail 전송관련 테이블 Insert, Mail 발송 * Input : string[] rParams * Output : String *************************************************************/ public string SetMailSend(params object[] rParams) { string xRtn = Boolean.FalseString; Database db = base.GetDataBase("LMS"); OracleConnection xCnnLMS = (OracleConnection)db.CreateConnection(); xCnnLMS.Open(); OracleTransaction xTransLMS = null; OracleCommand xCmdLMS = null; try { string xFilePath = string.Empty; xTransLMS = xCnnLMS.BeginTransaction(); // 트랜잭션 시작 xCmdLMS = base.GetSqlCommand(db); xCmdLMS.Connection = xCnnLMS; xCmdLMS.Transaction = xTransLMS; string xSeq = GetMaxIDOfCode(new string[] { "seq" }, xCmdLMS); string[] rMasterParams = (string[])rParams[0]; object[] rDetailParams = (object[])rParams[1]; try { string xSql = "INSERT INTO t_sent_mail_box ( "; xSql += " seq, mail_sub, sent_mail, rec_count, rec_email, open_course_id, user_id, sent_duty_step, sent_dt, ins_id, ins_dt) "; xSql += " VALUES ( "; xSql += string.Format(" {0}, ", xSeq); // SEQ (순번) xSql += string.Format(" '{0}', ", rMasterParams[0].ToString()); // mail_sub (메일제목) xSql += string.Format(" '{0}', ", rMasterParams[1].ToString()); // sent_mail (메일내용) xSql += string.Format(" {0}, ", Convert.ToInt32(rMasterParams[2])); // rec_count (발신자 총원) xSql += string.Format(" '{0}', ", rMasterParams[3].ToString()); // rec_email 수신자 메일 주소 (구분자는 ';') xSql += string.Format(" '{0}', ", rMasterParams[4].ToString()); // open_course_id (개설과정 ID) xSql += string.Format(" '{0}', ", rMasterParams[5].ToString()); // user_id (발신자 ID) xSql += string.Format(" '{0}', ", rMasterParams[6].ToString()); // sent_duty_stpe 발신자 직급 xSql += string.Format(" {0}, ", "SYSDATE"); // SENT_DT 발송일자 xSql += string.Format(" '{0}', ", rMasterParams[5].ToString()); // 등록자 ID xSql += string.Format(" {0}) ", "SYSDATE"); xCmdLMS.CommandText = xSql; base.Execute(db, xCmdLMS, xTransLMS); Rebex.Mail.MailMessage xMsg; xMsg = new Rebex.Mail.MailMessage(); xMsg.From = "HANJIN SM" + "<" + rMasterParams[8] + ">"; if (rMasterParams[9] == Boolean.TrueString) { xMsg.Bcc = rMasterParams[3]; } else { xMsg.To = rMasterParams[3]; } xMsg.Subject = rMasterParams[0]; xMsg.BodyText = rMasterParams[1]; if (rDetailParams.Length != 0) { foreach (object obj in rDetailParams) { HttpPostedFile xFile = (HttpPostedFile)obj; byte[] xFileData = new byte[xFile.ContentLength]; xFile.InputStream.Read(xFileData, 0, xFile.ContentLength); string[] xFileNameSector = xFile.FileName.Split(new char[] { '\\' }); string xFileName = xFileNameSector[xFileNameSector.Length - 1]; xFilePath = rMasterParams[7].ToString() + xFileName; FileStream xNewFile = new FileStream(xFilePath, FileMode.Create); xNewFile.Write(xFileData, 0, xFileData.Length); // byte 배열 내용을 파일 쓰는 처리 xNewFile.Close(); // 파일 닫는 처리 Rebex.Mail.Attachment att = new Rebex.Mail.Attachment(xFilePath); xMsg.Attachments.Add(att); xSql = string.Empty; xSql += " INSERT INTO t_sent_mail_box_att ( "; xSql += " seq, att_file) "; xSql += " VALUES ( "; xSql += string.Format(" {0}, ", xSeq); xSql += string.Format(" '{0}') ", xFileName); xCmdLMS.CommandText = xSql; base.Execute(db, xCmdLMS, xTransLMS); } } // Live Rebex.Net.Smtp.Send(xMsg, "smtp.hanjin.com"); // Test //Rebex.Net.Smtp.Send(xMsg, "testmail.hanjin.com"); //Rebex.Net.Smtp.SendDirect(xMsg); //xMsg.Send(xMsg); //Rebex.Net.Smtp smtp = new Rebex.Net.Smtp(); //smtp.Connect("col380b.cyberlogitec.com"); //smtp.Login("kmk", "kims1203"); //smtp.Send(xMsg); //Rebex.Net.Smtp.Send(xMsg, "col380b.cyberlogitec.com"); xTransLMS.Commit(); // 트랜잭션 커밋 xRtn = Boolean.TrueString; } catch (Exception ex) { // 파일 제거 if (xFilePath.Trim() != "") { File.Delete(xFilePath); } xTransLMS.Rollback(); // Exception 발생시 롤백처리... throw ex; } finally { if (xCmdLMS != null) { xCmdLMS.Dispose(); } if (xTransLMS != null) { xTransLMS.Dispose(); } } } catch (Exception ex) { throw ex; } return(xRtn); }
private void TestReadMailsFromDropFolder() { DirectoryInfo dropFolder = new DirectoryInfo(@"c:\temp\maildrop\"); DirectoryInfo sentFolder = new DirectoryInfo(@"c:\temp\sentmail\"); FileInfo[] files = dropFolder.GetFiles("*.eml"); foreach (FileInfo file in files) { Console.WriteLine(file.FullName); Rebex.Mail.MailMessage message = new Rebex.Mail.MailMessage(); message.Load(file.FullName); Console.WriteLine("s={0}, to={1}, from={2}", message.Subject, message.To, message.From); /* // Send mail using Rebex. SmtpConfiguration smtpConfiguration = new SmtpConfiguration(); smtpConfiguration.ServerName = "smtp.gmail.com"; smtpConfiguration.ServerPort = 587; smtpConfiguration.UserName = "******"; smtpConfiguration.Password = "******"; smtpConfiguration.Security = SmtpSecurity.Secure; //<smtp host="smtp.gmail.com" port="587" ssl="True" username="******" password="******"/> Smtp.Send(message, smtpConfiguration); */ MailMessage mm = MailMessageConverter.Convert(message); ISmtpClient s1 = new BasicSmtpClient(); ISmtpClient s2 = new FilteringSmtpClient(s1); s2.Send(mm); file.MoveTo(sentFolder.FullName+"\\"+file.Name); } }
private StoredMailMessage LoadMailFromFile(FileSystemInfo first) { // load mail FileInfo file = new FileInfo(first.FullName); string fileNameLoading = first.FullName + ".loading"; file.MoveTo(fileNameLoading); Rebex.Mail.MailMessage rmessage = new Rebex.Mail.MailMessage(); rmessage.Load(fileNameLoading); file.MoveTo(first.FullName + ".loaded"); StoredMailMessage mm = new StoredMailMessage(first.Name); MailMessageConverter.ConvertTo(rmessage, mm); file.MoveTo(first.FullName + ".ready"); return mm; }