Sending mail using SmtpClient in .net

前端 未结 5 1441
一整个雨季
一整个雨季 2021-02-07 02:19

I am unable to send the mail using smtp client. here is the code:

SmtpClient client=new SmtpClient(\"Host\");
client.Credentials=new NetworkCredential(\"username         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 02:43

    Try this :

    MailMessage mail = new MailMessage("emailfrom","emailto");
    
    mail.From = new MailAddress("emailfrom");
    mail.Subject = txtsbjct.Text;
    string Body = txtmsg.Text;
    mail.Body = Body;
    
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
    smtp.Credentials = new System.Net.NetworkCredential("youremail", "yourpassword");
    
    smtp.EnableSsl = true;
    smtp.Send(mail);
    txtemail.Text = "";
    txtmsg.Text = "";
    txtsbjct.Text = "";
    Label1.Text = "your email has been send";
    mail = null;
    smtp = null;
    

提交回复
热议问题