是否可以编写如下 C# 代码并使用不同国家的网络发送电子邮件?

发布于 2024-08-30 14:16:00 字数 461 浏览 4 评论 0原文

是否可以编写如下 C# 代码并在不同国家使用 mnetwork 发送电子邮件?

MSExchangeWebServiceURL = mail.something.com/ews/exchange.asmx

这是一个 Web 服务 URL。当我从家庭网络(我朋友的家庭网络)在任何地方运行相同的代码时,这非常有效,但是当我从哥伦比亚的客户位置运行它时,它会失败。

我在该 Exchange Server 上拥有有效的用户名和密码。我可以设置任何配置来实现此目的吗?

顺便说一句,当我在办公室网络和任何家庭网络中的任何网络中运行下面的代码时,它就可以工作。我至少在德克萨斯州普莱诺的五个朋友网络中尝试过。我希望这段代码可以在另一个国家/地区的任何网络上运行。

我在哥伦比亚的客户可以使用相同的用户名和密码使用浏览器连接到 Web 服务,但是当我运行上面的代码时,它无法连接到我们的 Web 服务。

Is it possible to write C# code as below and send email using mnetwork in different country?

MSExchangeWebServiceURL = mail.something.com/ews/exchange.asmx

It's a web service URL. This works great when I run the same code from home network, my friends home network anywhere around, but when I run it from my client's location in Columbia it fails.

I have a valid user name and password on that Exchange Server. Is there any configuration that I can set to achieve this?

BTW this code below works when I run it within office network and any network within any home network. I have tried it at least with five friends network in Plano, Texas. I want this code to work running from any network in another country.

My client in Columbia can connect to the web service using a browser using the same user name and password, but when I run the code above it is not able to connect to our web service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬シ愛 2024-09-06 14:16:00

编辑:根据评论和更新的帖子,我敢打赌客户端位置有阻止流量的代理服务器或防火墙。客户端可能需要将相关域添加到任何“白名单”中他们有。

如果它在内部网络上工作,那么问题很可能不是代码。您需要对其进行调试,看看在网络之外运行它时会出现什么错误。然后检查防火墙和目标交换服务器上的日志,看看发生了什么。

一个可能的罪魁祸首是 DNS 名称未在办公室网络之外设置,或者办公室防火墙未设置为将流量(或仅传递 SMTP 流量)从 Internet 传递到相关服务器。另一个原因是 Exchange Web 服务未正确设置以接受来自外部世界的请求。可以从 http://www.testexchangeconnectivity.com/ 进行测试。

如果这还不足以让您到达那里,请发布有关您所看到的错误的更多信息。 “它不起作用,我希望它起作用”有点让我想起《星际迷航》TNG 剧集< /a> 关于不断告诉乔迪“让它过去”的物种。

EDIT: Based on the comments and updated post, I would wager that the client location has a proxy server or firewall that is blocking the traffic. The client probably needs to add the relevant domain to whatever "whitelist" they have.

If it works from an internal network, then the problem is most likely not the code. You need to debug it and see what error turns up when running it outside of the network. Then check the logs on the firewall and the target exchange server to see what is happening.

One possible culprit is that the DNS name is not setup outside the office network, or that the office firewall is not setup to pass traffic (or only to pass SMTP traffic) from the internet to the server in question. Another is that Exchange Web Services is not setup properly to accept requests from the outside world. That can be tested from http://www.testexchangeconnectivity.com/.

If this isn't enough for you to get there, post more info about what errors you are seeing. "It isn't working, I want it to work" kind of reminds me of the Star Trek TNG episode about the species who kept telling Geordi to "make it go".

缪败 2024-09-06 14:16:00

如果您询问代码是否有效(看起来不像,但它在您的帖子中),您应该在 stackoverflow 上询问。如果您想知道为什么它不能在家工作,很可能是因为边缘服务器未设置为中继,如果您在家并且没有通过 VPN 连接到网络,那么您只能访问该网络。

If you are asking if the code works (which it doesn't look like you are but it's in your post) you should ask on stackoverflow. If you are wondering why it won't work from home Its likely because the edge server is not set up to relay, and if you are at home and not vpn'd into the network that's all you have access to.

捂风挽笑 2024-09-06 14:16:00

您需要稍微分解一下:

MSExchangeWebServiceURL 是什么?我不需要知道您的真实 URL,但这可以从您的家庭网络解析吗?即它是内部 DNS 主机 (server.mycompany.local) 还是外部可解析的 DNS 主机 (mail.yourcompany.com)?

如果它是内部的,就像另一位发帖者所说的那样,您至少需要使用 VPN(或将其替换为外部 URL)。

我不太擅长 C#,但我猜它正在寻找您的 Exchange Server 主机名或 FQDN,并且由于类型是“SMTP”,它希望与您的邮件服务器建立 TCP 会话。您可以通过打开命令提示符并尝试 telnet来测试这一点。 25 。当它起作用时,我猜你的代码也会起作用。

You need to break this down a bit:

What's the MSExchangeWebServiceURL? I don't need to know your real URL, but is this resolvable from your home network? i.e. is it an internal DNS host (server.mycompany.local) or is it an externally-resolvable DNS host (mail.yourcompany.com)?

If it's internal, like another poster said, you'll at least need to VPN in (or replace that with the external URL).

I'm not a big C# guy, but I'm guessing it's looking for your Exchange Server hostname or FQDN, and since the type is "SMTP" it wants to establish a TCP session with your mail server. You can likely test this out by opening up your command prompt and trying to telnet <MSExchangeWebServiceURL> 25. When that works, my guess is your code will work too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文