我在发送邮件时遇到问题. [英] i have problem when i am sending mail.

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

问题描述

我正在创建窗口应用程序.当我发送邮件时,那时会发生错误
无法发送消息:发送邮件失败.
您能告诉我代码中的问题是什么吗?

I am creating window application. When I am sending a mail, at that time error occur
Cannot sent Message : Failure sending mail.
Can you tell me what is the problem in my code.

try
{
                MailMessage mail = new MailMessage(txtfrom.Text, txtto.Text);
                mail.From = new MailAddress(txtfrom.Text);
                mail.To.Add(txtto.Text);
                mail.Subject = txtsubject.Text;
                mail.Body = txtmess.Text;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "mail.mycompanyid.net";
                smtp.Port = 25;
                NetworkCredential NetCrd = new NetworkCredential();
                NetCrd.Domain = "ip";
                NetCrd.UserName = "myid";
                NetCrd.Password = "mypass";
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = NetCrd;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Send(mail);
                MessageBox.Show("Your Message Sent Successfully");
            }
            catch (Exception ee)
            {
                MessageBox.Show("Cannot send message: " + ee.Message);
            }

推荐答案

[与ASP.NET相关的内容已删除]

看看winforms的这个技巧:
使用C#发送带有或不带有附件的电子邮件: [
[Content related to ASP.NET removed]

Have a look at this Tip for winforms:
Sending an Email in C# with or without attachments: generic routine.[^]


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

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