STMP送信メール(winformとasp.netで実行可能)

1753 ワード

MailMessage Msg = new MailMessage("\"    \" <   >", "\"  \" <   >");
                //      ,              
                Msg.Subject = "        !";//     
                Msg.IsBodyHtml = false;//     HTML   
                Msg.Body = "       !      :" + v + ",       www.f1188.com   ";
                SmtpClient objEmail = new SmtpClient("smtp.qq.com"); //SMTP      ,  GMail smtp.gmail.com
                objEmail.Credentials = new NetworkCredential("[email protected]", "  ");
                objEmail.EnableSsl = false; //        ,GMail        ,         false
                objEmail.Send(Msg);
具体的な事例
private void btnSend_Click(object sender, EventArgs e)
        {
            SendMail();
        }

        private void SendMail()
        {
            string from = "[email protected]";
            string to = "[email protected]";
            string subject = "Tank Bug  ";
            string body = txtMail.Text;
            string server = "smtp.163.com";
            MailMessage message = new MailMessage(from, to, subject, body);
            SmtpClient client = new SmtpClient(server);
            client.Credentials = new NetworkCredential("qq1989hn", "qq1989");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            MessageBox.Show("      !");
            this.Close();
        }