■ MailMessage 클래스 : 다음 메일 보내기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


Program.cs

 

 

using System.Web.Mail;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        private static void Main()

        {

            string subject  = "테스트 메일";

            string content  = "테스트 메일 입니다.";

            string from     = "testuser@daum.net";

            string to       = "testuser@daum.net";

            string account  = "testuser";

            string password = "testpassword";

 

            SendDaumMail(subject, content, from, to, account, password);

        }

 

        #endregion

 

        #region 다음 메일 보내기 - SendDaumMail(subject, content, from, to, account, password)

 

        /// <summary>

        /// 다음 메일 보내기

        /// </summary>

        /// <param name="subject">제목</param>

        /// <param name="content">내용</param>

        /// <param name="from">FROM 메일 주소</param>

        /// <param name="to">TO 메일 주소</param>

        /// <param name="account">계정</param>

        /// <param name="password">패스워드</param>

        private static void SendDaumMail(string subject, string content, string from, string to, string account, string password)

        {

            #pragma warning disable 0618

 

            MailMessage mailMessage = new MailMessage();

 

            mailMessage.Subject = subject;

            mailMessage.Body    = content;

            mailMessage.From    = from;

            mailMessage.To      = to;

 

            mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl"      , true    );

            mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport"  , 465     );

            mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1       );

            mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername"    , account );

            mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword"    , password);

 

            SmtpMail.SmtpServer = "smtp.daum.net";

 

            SmtpMail.Send(mailMessage);

 

            #pragma warning restore 0618

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker