.NET에서 이메일을 보내는 방법

6168 단어

이메일.cs




using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace email_sending
{
    public partial class email : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void send_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smpt = new SmtpClient();
                message.From = new MailAddress("Enter Your Email Here");
                message.To.Add(new MailAddress(to.Text));
                message.Subject = "Testing";
                message.IsBodyHtml = true;
                message.Body = body.Text;
                smpt.Port = 587;
                smpt.Host = "smtp.office365.com";
                smpt.EnableSsl = true;
                smpt.UseDefaultCredentials = false;
                smpt.Credentials = new NetworkCredential("Enter Your Email Here", "Enter Your Passwrod");
                smpt.DeliveryMethod = SmtpDeliveryMethod.Network;
                smpt.Send(message);
            } catch (Exception ex)
            {

            }
        }
    }
}


폴더 구조







Read More

좋은 웹페이지 즐겨찾기