System.Net.Mail设置 [英] System.Net.Mail setup

查看:90
本文介绍了System.Net.Mail设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此类时,我在互联网上看到的示例为何不包含端口号,用户名和密码以及服务器名的声明?

我将在客户端上使用此类应用程序,我想我需要提供此信息,但不知道如何编码.

When using this class how come the examples I see on the internet do not include statements for port number, username and password, and servername?

I''m going to be using this class on a client app and I think I need to supply this information but do not know how to code it.

推荐答案

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient([Host], [Port]);<br />smtp.Credentials = new System.Net.NetworkCredential([UserName], [Password]);


如果愿意,请使用配置文件(web.config,app.config).


If you prefer, use the config file (web.config, app.config).

<system.net&gt<br />	<mailSettings><br />		<smtp><br />			<network host="" port="" userName="" password="" /><br />		</smtp><br />	</mailSettings><br />&lt/system.net>


我看到了很多例子,但它们并不能给您真正的例子.

请参见此处 [ ^ ]和此处 [
I have seen many that give examples, but they wont give you real working one.

See here[^] and here[^] for code examples


您需要使用 System.Net.Mail.Smtp客户端 [ ^ ]和然后 SmtpClient.Credentials [
You need to use System.Net.Mail.SmtpClient[^] and then SmtpClient.Credentials[^].

Simple credential:
client.Credentials = new System.Net.NetworkCredential(username, password);






这篇关于System.Net.Mail设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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