电子邮件未生成 [英] Emails not getting generated

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

问题描述

您好,我正在尝试为网络表单设置电子邮件选项.但是,如果我不设置任何条件并尝试发送常规电子邮件,则可以正常工作,但是如果我尝试设置任何条件,以便根据报告类型向其发送不同的配方.页面再次加载,但没有发送电子邮件.这是发送电子邮件的代码.如果您能帮我解决这个问题,这真的很有帮助.

Hi, I''m trying to setup email options for a web form.However if i don''t put any condition and try to send a general email, it works, but if at all i try to put any condition as to send it different recipents depending on the report type.The page loads up again but no email is sent.Here is the piece of code for sending the email.It would really helpful if you could help me out with this.

foreach (GridViewRow row in reportTable.Rows)
            {
                foreach (dbTypes.report report in reports)
                {

                    CheckBox cb = (CheckBox)row.Cells[8].FindControl("cb");
                    cb = (CheckBox)reportTable.Rows[i].Cells[8].FindControl("cb");
                    testBench b = new testBench();

                    if (cb.Checked && b.costPos == "123")
                    {
                        MailMessage message = new MailMessage("no-reply@gmail.com",
               "tony.romo@gmail.com", "Kostenstelle  : 123",
               "Kostenstelle : 123");


                        /* create SMTP Client and add credentials */
                        SmtpClient smtpClient = new SmtpClient("SERVER");
                        smtpClient.UseDefaultCredentials = true;
                        /* Email with Authentication */
                        //smtpClient.Credentials = new NetworkCredential("userID",
                        //"password", "domainName");

                        /*Send the message */
                        smtpClient.Send(message);
                    }

推荐答案



可能的问题:

1)cb发生异常.检查是否未选中复选框.
2)您的条件不满足,如果有代码,则无法执行.

解决方案:

1)添加try ... catch块并检查是否发生任何异常.
2)添加其他条件并提示相应的消息.

谢谢
-Amit Gajjar
Hi,

Possible issues:

1) Exception occur at cb.Checked if checkbox not found.
2) Your condition is not met and it is not able to execute if code.

Resolution:

1) Add try ...catch block and check if any exception occur.
2) add else condition and prompt appropriate message.

Thanks
-Amit Gajjar


您好,请参考,

www.codeproject.com/Articles/12511/ASP-Net-2-0-Feed-back-Form中的发送电子邮件 [
hii refer this ,

www.codeproject.com/Articles/12511/Send-Email-in-ASP-Net-2-0-Feed-back-Form[^]


好吧,我看到了,您没有如果您的SMTP服务器支持中继,则不提供任何用户名/密码.

检查代码,
Well, what I see, you didn''t provide any user name/password, if your SMTP server supports relay.

Check the code,
smtpClient = new SmtpClient();
System.Net.NetworkCredential credentials = null;
smtpClient.Port = int_port;
smtpClient.Host = str_server;
if (str_ssl == "SSL")
{
    smtpClient.EnableSsl = true;
}
else
{
    smtpClient.EnableSsl = false;
}
if (str_isauthenticate == "Yes")
{
    smtpClient.UseDefaultCredentials = false;
    credentials =
            new System.Net.NetworkCredential(str_user, str_password);

    smtpClient.Credentials = credentials;
}
else
{
    smtpClient.UseDefaultCredentials = true;
    credentials =
            new System.Net.NetworkCredential();
    smtpClient.Credentials = credentials;

}



希望这会有所帮助.
欢呼



Hope this helps.
cheers


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

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