Common C#/C# BEST TIP2009. 4. 30. 13:59
 사연 : C# 으로 Mail 발송 부분을 구현 하고 ->
         해당 C#의 DLL을 파워빌더에서 사용 하기 위한 작업 이다.

1. C# DLL을 C++에서 사용 해보자. (ㅡ,.ㅡ 허접한 메일 보내기 라이브러리)

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

    }
}


해당 내용을 클래스 라이브 러리로 만듭니다. 또한 사용할 Method는 Interface에서 선언을 해주어야 가따가 쓸 수 있습니다.

속성 -> 응용 프로그램 -> 어셈블리정보에서
 
어셈블리를 COM에 노출을 클릭 해야 한다.
Posted by penguindori