如何从我的C#应用​​程序发送电子邮件? [英] How do I send an email message from my C# application?

查看:172
本文介绍了如何从我的C#应用​​程序发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我写的代码:

        MailMessage mail = new MailMessage("test@gmail.com", "me@myurl.com");

        mail.Subject = "This is a test!!";
        mail.Body = "testing...";

        SmtpPermission connectAccess = new SmtpPermission(SmtpAccess.Connect);
        System.Console.WriteLine("Access?  " + connectAccess.Access);

        SmtpClient client = new SmtpClient("mail.myurl.com", 2525);
        client.Send(mail);



它不工作。我得到的线异常client.Send(邮件),上面写着邮箱不可用的服务器响应(MYLOCALCOMPUTERNAME)[我的本地IP]。3045目前不允许通过中继

It's not working. I get an exception at the line "client.Send(mail)" that says "Mailbox unavailable. The server response was (MYLOCALCOMPUTERNAME) [MY LOCAL IP]:3045 is currently not permitted to relay through."

connectAccess.Access不会返回连接(我不知道这是否是必要的......我在添加它来启动故障排除过程。)

connectAccess.Access does return "Connect" (I'm not sure if this was necessary... I added it in to start the troubleshooting process.)

这是否意味着我的本地机器以某种方式进行配置?什么时候我的应用程序部署到其他民族的机器?请问我们需要有本地配置呢?我只是希望创造一个发送反馈式的从我的应用程序链接

Does this mean that my local machine has to be configured in some way? What about when I deploy my app to other peoples machines? Will there need to be local configuration there? I'm just looking to create a "Send Feedback" type of link from my application.

(注:在我的实际应用中我用我的真实电子邮件地址均在到和从我的SMTP是真的在承载我的网址/网站的地方我的SMTP地址)

(Note: in my real application I am using my real email addresses in both the "to" and "from" and my smtp is really my smtp address at the place that hosts my url/website)

谢谢!

-Adeena

推荐答案

@迈克尔:感谢您的链接。这是非常有帮助的。

@ Michael: thanks for the link. It's very helpful.

我的认为的我想通了,我的问题。我需要我创造了我的客户对象之后,再添加登录凭据。我添加了以下行:

I think I figured out my problem. I did need to add the login credentials after I created my "client" object. I added the following line:

 client.Credentials = new System.Net.NetworkCredential("myloginat+myurl.com", "mypassword");



(对不起 - 我有这个习惯后,我寻找一个答案在网络上,并通过我的手册2小时后,我终于打破和发布问题,然后在5分钟后看着办吧。:)我觉得写下来的问题的行为可以帮助我比什么都重要)

(sorry - I have this habit that after I search for an answer on the web and through my manuals for 2 hrs, I finally break down and post the question and then 5 minutes later figure it out. :) I think the act of writing down the question helps me more than anything else)

所以它的工作...虽然我不会要求我了解我如何以及为什么它的工作,所以希望我给予我的程序给他人使用在运行一些问题的一切。即,将每个人都使用具有互联网连接能够打开此SMTP连接到我的服务器的程序?我不知道这个问题的答案......我将不得不等待,看看,多学习一些。

So it's working... although I won't claim I understand everything about how and why it's working so I do expect to run in to some problems as I give my program to others to use. i.e., will everyone using the program that has an internet connection be able to open this smtp connection to my server? I don't know the answer to that... I'll have to wait, see, and learn some more.

谢谢! :)

-Adeena

这篇关于如何从我的C#应用​​程序发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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