无法发送邮件 [英] unable to send mail

查看:101
本文介绍了无法发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

   }

    protected void btnSend_Click(object sender, EventArgs e)
   {
        MailMessage mail = new MailMessage();
        mail.To.Add(txtTo.Text);
        mail.From = new MailAddress(txtFrom.Text);
        mail.Subject = txtSubject.Text;
        mail.Body = txtMessage.Text;
        mail.IsBodyHtml = true;
        if (FileUpload1.HasFile)
        {
            mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
        }
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; 
        smtp.Credentials = new System.Net.NetworkCredential("YourGmailID@gmail.com", "YourGmailPassword");
        smtp.EnableSsl = true;
        smtp.Send(mail);
    }
}


上面是我使用的代码,但是我无法接收邮件..可能是什么问题,请帮忙..web.config文件中的


above is the code i used but i am unable to receive the mail .... what can be the possible problem please help ..

推荐答案

添加这些行,我认为它将解决您的问题

in web.config file add these lines i think it will solve your problem

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="PickupDirectoryFromIis"/>
    </mailSettings>
  </system.net>
  <system.web>
    <authentication mode="Forms" />
  </system.web>


我认为您需要通过GMail发送电子邮件,请在SmtpClient对象上设置Port的属性(在您的情况下为smtp)到465或587.
I believe that you need to send email via GMail, please set the property of Port on the SmtpClient object (in your case it is smtp)to 465 or 587.



再添加一行您的代码
Please
add one more Line your code
smtp.UseDefaultCredentials = false;


我希望它能起作用.


i hope it work.


这篇关于无法发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆