通过c#代码发送电子邮件 [英] Sending emails via c# code

查看:76
本文介绍了通过c#代码发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我用谷歌搜索了这个并找到了一些答案,但没有一个给我的确是

我在追求什么,也许有人在这里可以帮忙。


我有一个应用程序,将分发给用户的笔记本电脑和

家用电脑,我不知道什么操作系统他们正在使用虽然它们至少是Win 98,但我也不知道他们将使用什么邮件客户端或者他们的邮件帐户使用哪个ISP。我想

使用他们的默认邮件帐户从应用程序发送一封电子邮件,我有一个

看看System.Web.Mail类,特别是MailMessage类,但是

这需要一个邮件服务器,我如何从

系统获取这些信息?它还需要一个来自现场的邮件,我希望从系统中获得
而不要求用户输入它,再次如何实现这个




还有另外一种方法可以做我想做的事情,我知道有一些

Indy组件,但我宁愿避免更多的Dll''' s,

除非Indy路线是最好的。


我唯一可以保证的是这款应用的目标机器
$ b安装$ b将有一个邮件帐户。


非常感谢


Joe

Hi all,

I have googled this and found some answers but none that give me exactly
what I''m after, maybe someone here can help.

I have an app that will be distributed to users for their laptop and
home PC''s, I have no idea what operating system they are using although
it will be at least Win 98, I also have no idea what mail client they
will be using or which ISP their mail account is with. I would like to
send an email from the app using their default mail account, I had a
look at the System.Web.Mail classes, specifically MailMessage class, but
this requires a mail server, how would I get this information from the
system? also it requires a mail from field which I would like to get
from the system without asking the user to enter it, again how is this
achieved?

Is there another way to do what I want to do, I know that there are the
Indy components but I''d rather avoid having to distibute more Dll''s,
unless the Indy route is the best.

The only thing I can guarantee is that the target machine that this app
is installed on will have a mail account.

Many thanks

Joe

推荐答案

我会在你的应用程序中构建一个可配置的SMTP服务器属性。


尽可能尝试并标准化地址 - 也许使用机器
名称或当前登录名。


" Joe_Black" <乔****** @ newsgroups.nospam>在消息中写道

新闻:%2 *************** @ TK2MSFTNGP12.phx.gbl ...
I would build the SMTP server property as configurable in your application.

Try and standardise the from address if possible - maybe use the machine
name or currently login name.

"Joe_Black" <Jo******@newsgroups.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
大家好,

我用谷歌搜索了这个并找到了一些答案,但没有一个能给我准确的
我在追求什么,也许有人在这里可以提供帮助。

我有一个应用程序将分发给用户的笔记本电脑和家用电脑,我不知道他们正在使用什么操作系统,虽然它至少会是Win 98,我也不知道是什么邮件客户端他们将使用或他​​们的邮件帐户与哪个ISP。我想使用他们的默认邮件帐户从应用程序发送一封
电子邮件,我看了一下
System.Web.Mail类,特别是MailMessage类,但这需要
一封邮件服务器,我如何从系统获取此信息?它还需要一个来自现场的邮件,我想从系统中获取
而不要求用户输入它,又是如何实现的呢?

还有另外一种方法吗?做我想做的事情,我知道有一些Indy组件,但我宁愿避免更多的Dll',而且除非Indy路线是最好的。

我唯一可以保证安装此应用程序的目标机器将有一个邮件帐户。

非常感谢
Joe



Adam Barker写道:
Adam Barker wrote:
我会在您的应用程序中构建可配置的SMTP服务器属性。

" Joe_Black" <乔****** @ newsgroups.nospam>在消息中写道
新闻:%2 *************** @ TK2MSFTNGP12.phx.gbl ...


亚当,


嗯,我想认为用户会有能力进入

smtp服务器详细信息:-),但是我们的目标受众真的不是那个

计算机文化。此外,应用程序的电子邮件部分唯一需要的时间是他们注册他们的软件,所以理想情况下我希望它能够成为一个简单的例子。点击并查看它们。

如果可能,尝试并标准化地址 - 也许使用
机器名称或当前登录名。
I would build the SMTP server property as configurable in your application.
"Joe_Black" <Jo******@newsgroups.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...

Hi Adam,

Hmmm, I''d like to think the users would have the abilty to do enter the
smtp server details :-), however our target audience wont really be that
computer literate. Also the only time the email part of the app will be
needed is when they register their software, so ideally I''d like it to
be a simple case of click and go for them.
Try and standardise the from address if possible - maybe use the
machine name or currently login name.




这是否意味着来自地址不一定是有效的电子邮件

地址?即


他们的实际电子邮件是
so*****@ansmtpserver.com


但是MailMessage对象中的起始地址可以设置为
re ********** @ adomain.com


非常感谢

Joe



Does this mean that the from address does not have to be a valid email
address? i.e.

Their actual email is
so*****@ansmtpserver.com

but the from address in the MailMessage object could be set to
re**********@adomain.com

Many thanks
Joe


我无法看到你如何处理所有不同的配置,而不是以编程方式检查Outlook配置文件的属性为例如
。即使

这依赖于使用Outlook的用户。


您可以在第一次安装后让应用程序询问服务器然后

再也不会打扰用户。然后你只需要让用户知道所需的

详细信息,即他们的SMTP服务器。 (如果你知道他们的IP,你可以

提前查看它以帮助他们)


''from''地址是你的选择一定程度。不可否认,当我控制SMTP服务器本身时,我只有
使用自定义地址

并且可以启用中继等。


" Joe_Black" <乔****** @ newsgroups.nospam>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
I can''t see how you could cope with all the different configurations without
programmatically checking properties of an Outlook profile for example. Even
this relies on the user using Outlook.

You could make the app ask for the server after first installing and then
never bother the user again. Then you just need to let the user know the
details required, i.e. their SMTP server. (If you know their IP, you could
look this up in advance to help them)

The ''from'' address is your choice to a certain extent. Admittedly I''ve only
used a custom address when I''ve been in control of the SMTP server itself
and can enable relaying etc.

"Joe_Black" <Jo******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Adam Barker写道:
Adam Barker wrote:
我会在你的
应用程序中构建可配置的SMTP服务器属性。

" Joe_Black" <乔****** @ newsgroups.nospam>在消息中写道
新闻:%2 *************** @ TK2MSFTNGP12.phx.gbl ...
I would build the SMTP server property as configurable in your
application.
"Joe_Black" <Jo******@newsgroups.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...



嗨亚当,

嗯,我想认为用户会有能力进入
smtp服务器的详细信息:-),但是我们的目标受众真的不会那样
计算机知识。此外,应用程序的电子邮件部分唯一需要的时间是他们注册他们的软件,所以理想情况下我希望它是一个简单的点击并为他们服务的案例。 />



Hi Adam,

Hmmm, I''d like to think the users would have the abilty to do enter the
smtp server details :-), however our target audience wont really be that
computer literate. Also the only time the email part of the app will be
needed is when they register their software, so ideally I''d like it to be
a simple case of click and go for them.

尝试并尽可能标准化地址 - 也许使用机器名称或当前登录名。
Try and standardise the from address if possible - maybe use the machine
name or currently login name.



这是否意味着从地址不一定是有效的电子邮件地址?即

他们的实际电子邮件是
so*****@ansmtpserver.com

但是MailMessage对象中的from地址可以设置为
re * *********@adomain.com

非常感谢
Joe



Does this mean that the from address does not have to be a valid email
address? i.e.

Their actual email is
so*****@ansmtpserver.com

but the from address in the MailMessage object could be set to
re**********@adomain.com

Many thanks
Joe



这篇关于通过c#代码发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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