Mailmessage+smtpclient发送电子邮件时密码写在哪里?

qufo 2006-07-13 05:34:25
如下代码:
MailMessage msg = new MailMessage("mailfrom@163.com", "mailto@163.com", "Subject:Test", "Body:Test");
SmtpClient smtp = new SmtpClient("smtp.163.com");
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;

try
{
smtp.Send(msg);
}
catch (Exception exx)
{
MessageBox.Show(exx.Message);
}

可是,我的mailfrom@163.com的邮件登录密码写在哪?不写密码肯定发不出去呀。
...全文
887 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
牛人 2006-07-14
  • 打赏
  • 举报
回复
不写密码能发
foyuan 2006-07-14
  • 打赏
  • 举报
回复
1.x和2.0是不同的

2.0写在配置文件里面就行了
1.x需要添加Field
wxqq2001 2006-07-14
  • 打赏
  • 举报
回复
补充:

Smtp服务器,可用本地的也可以用其它的可用有Smtp服务器.
(1)如果用本地的,本地要装Smtp服务也就是系统组件,默认没有安装。
(2)如果用邮件服务商的,你要有其上面的帐号与密码。

SmtpClient.Credentials 属性:获取或设置用于验证发件人身份的凭据。

public static void CreateTestMessage1(string server, int port,string userName,string password)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server, port);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.Credentials = new System.Net.NetworkCredential(userName, password);

client.Send(message);
}
myminimouse 2006-07-13
  • 打赏
  • 举报
回复
up
linzi 2006-07-13
  • 打赏
  • 举报
回复
smtp.Credentials = new System.Net.NetworkCredential("mailfrom@163.com", "password");
z_liwu 2006-07-13
  • 打赏
  • 举报
回复
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _usename); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _userpwd); //set your password here
wxqq2001 2006-07-13
  • 打赏
  • 举报
回复
不需要登陆你的mailfrom@163.com的密码

有smtp服务就能发送出去. (也就是常说的垃圾邮件...)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧