using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.Mail;
namespace SMTPClient
{
[Guid("11116a57-63a0-4694-aab3-11111e4152f9")]
public interface InetSmtp
{
int prints(string str);
void smtpServer(string host, int port);
void address(string from, string to);
string Subject { get;set;}
string Body { get;set;}
void FileAppend(string file);
void smtpSend();
}
[Guid("13316a57-63c0-9694-ccb3-14441e4152f9")]
public class NetSmtpLibrary : InetSmtp
{
public int prints(string str)
{
System.Windows.Forms.MessageBox.Show(str);
return 33;
}
#region Field
SmtpClient smtp;
MailMessage msg;
#endregion
#region Server 설정 #1
public void smtpServer(string host, int port)
{
smtp = new SmtpClient(host, port);
System.Windows.Forms.MessageBox.Show(smtp.Port.ToString());
}
#endregion
#region mail 발송주소, 받는주소 지정 #2
public void address(string from, string to)
{
MailAddress _from = new MailAddress(from);
MailAddress _to = new MailAddress(to);
mailDesignate(_from, _to);
}
private void mailDesignate(MailAddress from, MailAddress to)
{
msg = new MailMessage(from, to);
}
#endregion
#region 제목, 내용을 설정 합니다. #3
public string Subject
{
get { return msg.Subject; }
set { msg.Subject = value; }
}
public string Body
{
get { return msg.Body; }
set
{
msg.Body = value;
msg.BodyEncoding = Encoding.Default;
}
}
#endregion
#region 첨부파일 #4
public void FileAppend(string file)
{
try
{
Attachment attach = new Attachment(file);
msg.Attachments.Add(attach);
}
catch (Exception ex)
{
System.Windows.Forms.
MessageBox.Show("FileAppend() : " + ex.Message.ToString());
}
}
#endregion
#region mail 보내기 시작 #5
public void smtpSend()
{
try
{
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.Send(msg);
}
catch (Exception ex)
{
System.Windows.Forms.
MessageBox.Show("smtpSend() : " + ex.Message.ToString());
}
}
#endregion
}
} |