电子邮件发送附件 [英] email send apllication

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

问题描述

我使用以下代码发送邮件.当我在localhost中测试时,它可以正常工作,但是当此代码在Web应用程序中使用时.我的注册表格已成功提交,但电子邮件未发送,也没有任何错误.请给我帮助.

I use the following code for sending mail .When i test in localhost it work properly but when this code use in web application. my registration form submitted successfully but the email does not send and not any error also. plz give me help.

string Subject = "Registration...";
        String Body = "Candidate Name : " + txtfname.Text + " " + txtsname.Text + "\n" + "Description : You Are Now Register With Us" + "\n" + "Your User Name Is :" + txtuname.Text + "And Password is :" + txtpass.Text + "\n" + "Thank You...";
        //lbldetail.Text;
        MailMessage mail = new MailMessage();

        mail.To.Add(txtmail.Text);
        mail.From = new MailAddress("vedbhavan2011@gmail.com");
        mail.Subject = Subject;
        mail.Body = Body;


        mail.IsBodyHtml = true;
        mail.Priority = System.Net.Mail.MailPriority.High;
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential("vedbhavan2011@gmail.com", "******");//password here
        client.Port = 587; // Gmail works on this port
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true; //Gmail works on Server Secured Layer
        try
        {
            client.Send(mail);
            lblmsg.Text = "Email Sent Successfully...";
        }
        catch
        {

        }

推荐答案

您错过了一个重要属性.

只需在下面添加行
You missed one important property.

Just add the line below
client.UseDefaultCredentials = false;


之前


before

client.Credentials = new System.Net.NetworkCredential("vedbhavan2011@gmail.com", 



这样的代码看起来就像是



So the code will look like,

client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("vedbhavan2011@gmail.com", 
....



让我知道它是否可以解决您的目的.

欢呼



Let me know if it solves your purpose.

cheers


您没有显示发生的错误

You are not displaying the error that happens

try
        {
            client.Send(mail);
            lblmsg.Text = "Email Sent Successfully...";
        }
        catch
        {

        }




做这个




do this

try
        {
            client.Send(mail);
            lblmsg.Text = "Email Sent Successfully...";
        }
        catch(Exception ex)
        {
            string str_ex = ex.Message;
            lblmsg.Text = str_ex;
        }



我在这里猜测,但我敢打赌,您的问题是生产服务器上的防火墙.它可能不允许通过端口587进行通信



I''m taking a guess here but I bet your problem is your firewall on your production server. It is probably not allowing communication through on port 587


在您的服务器中启动了smtp吗?
In your server have you start the smtp ?


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

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