Files
Unimarc/unimarc/unimarc/Email.cs
SeungHo Yang 6d1c7d8fe3 =====* ISBN 조회 *=====
Yes24 - 바뀐 예스 양식에 따라 수정

=====* unimarc *=====
- 목록등록 -
머리글에 맞춰 숫자 입력기능 추가

- 목록집계 -
거래처명 엔터시 검색 추가
추가정보 표출창에 거래처 정보가 출력됨

- 송금내역 -
엑셀 반출작업 완료

- 입고작업 -
gird3 isbn찍으면 책검색이 되어 자동으로 해당 isbn 책이 출력됨
2021-07-15 17:04:34 +09:00

196 lines
6.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mail;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
class Email
{
Helper_DB db = new Helper_DB();
public bool cross_mail(string compidx, string filePath, string sender)
{
#region Setup
db.DBcon();
// 보내는 이 : 메일ID, 메일PW, smtp주소, 포트번호
string sender_Area = "`comp_name`, `email_ID`, `email_PW`, `smtp`, `port`";
string tmp_db = db.DB_Select_Search(sender_Area, "Comp", "idx", compidx);
string[] arr_db = tmp_db.Split('|');
bool res = false;
bool daum = false;
if (arr_db[1].Contains("@daum.net") || arr_db[1].Contains("@hanmail.net"))
{
daum = true;
}
#endregion
if (daum)
{
res = Daum_Send_Mail(arr_db, filePath, sender);
}
else { res = Send_mail(arr_db, filePath, sender); }
if (res)
{
Resend_Mail(arr_db, filePath, sender, daum);
}
return res;
}
bool Daum_Send_Mail(string[] arr_db, string filePath, string sender)
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = arr_db[1];
msg.To = sender;
msg.Subject = string.Format("{0} 주문분입니다.", arr_db[0]);
msg.Body = string.Format("{0} 주문분입니다.", arr_db[0]);
msg.Attachments.Add(new MailAttachment(filePath));
int cdoBasic = 1;
string smtp_server = arr_db[3];
int port = Convert.ToInt32(arr_db[4]);
string field = "http://schemas.microsoft.com/cdo/configuration/";
msg.Fields.Add(field + "smtpusessl", true);
msg.Fields.Add(field + "smtpserverport", port);
msg.Fields.Add(field + "smtpauthenticate", cdoBasic);
msg.Fields.Add(field + "sendusername", arr_db[1]);
msg.Fields.Add(field + "sendpassword", arr_db[2]);
try
{
SmtpMail.SmtpServer = smtp_server;
SmtpMail.Send(msg);
MessageBox.Show("다음 메일 전송 성공");
return true;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return false;
}
}
bool Send_mail(string[] arr_db, string filePath, string sender)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
// 보내는 사람 이메일
mail.From = new MailAddress(arr_db[1]);
// 받는 사람 이메일
mail.To.Add(sender);
// 메일 제목
mail.Subject = string.Format("{0} 주문분입니다.", arr_db[0]);
// 메일 내용
mail.Body = string.Format("{0} 주문분입니다.", arr_db[0]);
// 첨부파일 붙이기
Attachment attachment = new Attachment(filePath);
mail.Attachments.Add(attachment);
string smtp_server = arr_db[3];
int port = Convert.ToInt32(arr_db[4]);
// SMTP 및 포트 설정
SmtpClient smtp = new SmtpClient(smtp_server, port);
smtp.EnableSsl = true;
// 계정 설정
smtp.Credentials = new NetworkCredential(arr_db[1], arr_db[2]);
try
{
smtp.Send(mail);
MessageBox.Show("메일 전송 완료");
return true;
}
catch (SmtpException e)
{
MessageBox.Show(e.ToString());
return false;
}
}
void Resend_Mail(string[] arr_db, string filePath, string sender, bool daum)
{
if (daum)
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = arr_db[1];
msg.To = arr_db[1];
msg.Subject = string.Format("(확인메일) {0} 주문분입니다.",arr_db[0]);
msg.Body = string.Format("(확인메일) {0} 주문분입니다.", arr_db[0]);
msg.Attachments.Add(new MailAttachment(filePath));
int cdoBasic = 1;
string smtp_server = arr_db[3];
int port = Convert.ToInt32(arr_db[4]);
string field = "http://schemas.microsoft.com/cdo/configuration/";
msg.Fields.Add(field + "smtpusessl", true);
msg.Fields.Add(field + "smtpserverport", port);
msg.Fields.Add(field + "smtpauthenticate", cdoBasic);
msg.Fields.Add(field + "sendusername", arr_db[1]);
msg.Fields.Add(field + "sendpassword", arr_db[2]);
try
{
SmtpMail.SmtpServer = smtp_server;
SmtpMail.Send(msg);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
else
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new MailAddress(arr_db[1]);
mail.To.Add(arr_db[1]);
mail.Subject = string.Format("(확인메일) {0} 주문분입니다.", arr_db[0]);
mail.Body = string.Format("(확인메일) {0} 주문분입니다.", arr_db[0]);
// 첨부파일 붙이기
Attachment attachment = new Attachment(filePath);
mail.Attachments.Add(attachment);
string smtp_server = arr_db[3];
int port = Convert.ToInt32(arr_db[4]);
// SMTP 및 포트 설정
SmtpClient smtp = new SmtpClient(smtp_server, port);
smtp.EnableSsl = true;
// 계정 설정
smtp.Credentials = new NetworkCredential(arr_db[1], arr_db[2]);
try
{
smtp.Send(mail);
}
catch (SmtpException e)
{
MessageBox.Show(e.ToString());
}
}
}
}
}