通过C#Windows应用程序发送电子邮件 [英] Send Email through a C# windows application
本文介绍了通过C#Windows应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好……
我已经在C#中创建了一个简单的Windows应用程序,我想在其中发送电子邮件.
我有一段代码要在这里发布.
我收到错误消息发送邮件失败".
任何人都可以更正我的代码吗?
hello everyone......
i have created a simple windows application in c# in which i want to send an email.
i have a piece of code that i am going to post here.
i got an error "Failure Sending Mail".
Can any one please correct my code .
public void myEmail(string sendTo, string sendFrom, string subjct,string bdy, string pass)
{
SmtpClient smtp = new SmtpClient("127.0.0.1",25);
MailAddress to = new MailAddress(sendTo);
MailAddress from = new MailAddress(sendFrom);
MailMessage message = new MailMessage(sendFrom, sendTo);
message.Subject = subjct;
message.Body = bdy;
smtp.Timeout = 50000;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(sendFrom, pass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.Send(message);
}
如果您纠正此代码,我将非常感谢您.
i will be highly thankful to you if you correct this code
推荐答案
您的代码没有错.我怀疑您的本地计算机(127.0.0.1)是电子邮件服务器还是中继服务器.
There is nothing wrong with your code. I doubt your local machine (127.0.0.1) is an email server or relay.
没有人可以解决您的问题,但是您可以尝试
1.将您的代码放在try/catch块中,查看您遇到的异常
2.检查您的机器是否已正确配置smtp
3.确保可以传递"到邮件服务器.
No one is going to fix your issues, but you can try
1. put your code in try / catch block and see the exception you are getting
2. Check that your machine has smtp configured right
3. Make sure you can ''pass-through'' to your mail server.
SmtpClient smtp = new SmtpClient(" 127.0.0.1 ",25) ;
您的本地计算机是smtp主机吗?您如何确定?
SmtpClient smtp = new SmtpClient("127.0.0.1",25);
Is your local machine is the smtp host? How can you make sure that?
这篇关于通过C#Windows应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文