发送邮件失败

时间:2019-10-11 02:44:00

标签: c# asp.net email

我将其上传到无法正常工作的服务器上。错误是:发送邮件失败。请告诉我问题出在哪里。

    string username = "abc@gmail.com";   
    string password = "abc";

    SmtpClient smtpclient = new SmtpClient("smtp.gmail.com");
    smtpclient.Port = 465;
    smtpclient.UseDefaultCredentials = false;
    smtpclient.Credentials = new System.Net.NetworkCredential(username, password);
    smtpclient.EnableSsl = true;
    smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();  
    MailAddress fromaddress = new MailAddress(username);   

    mail.From = fromaddress; 
    mail.To.Add("xxxxx@gmail.com");
    mail.Subject = ("Test Subject");
    mail.IsBodyHtml = true; logic
    mail.Body = TextBox2.Text;

    try
    {

        smtpclient.Send(mail);
        Response.Write("<B>Email Has been sent successfully.</B>");
    }
    catch (Exception ex)
    {

        Response.Write(ex.Message);

0 个答案:

没有答案