C#中的ASP.NET转换为MailAddress [英] c# asp .net Convert to MailAddress

查看:848
本文介绍了C#中的ASP.NET转换为MailAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作就是要自动发送电子邮件的应用程序。我在Web.config文件中的preferences(发件人,收件人等)。我想为前获得接收像下面的

I am working on an application that is going to send an email automatically. I have the preferences(sender,receiver etc...) in web.config file. I am trying for ex to get the receiver like the following

          MailMessage msg = new MailMessage();
        msg.To = ConfigurationManager.AppSettings["AdminEmail"];

我碰到下面的错误。
错误3无法隐式转换类型'字符串'到'System.Net.Mail.MailAddressCollection。任何帮助吗?

I get the following error. Error 3 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddressCollection'. Any help?

推荐答案

尝试使用采取一切弦两个构造函数之一 - 尤其是这一个从需要和到的电子邮件地址

Try using one of the two constructors that take all-strings - in particular this one that takes 'from' and 'to' email addresses.

new System.Net.Mail.MailMessage("from@from.com", 
  ConfigurationManager.AppSettings["AdminEmail"])

有也是其中一个接受主题(顺序)作为附加字符串参数为好。

There's also one which accepts a subject and body (in that order) as additional string parameters as well.

属性是 MailAddress ES的集合,因为你可以正确地发送电子邮件到一个以上的人。你不能,因此只分配字符串给它(它可能会帮助看一下MSDN上的文档?)

The To property is a collection of MailAddresses because you can rightly send an email to more than one person. You cannot, therefore just assign a string to it (it might help to look at the documentation on MSDN?)

您可以,但是,添加新的 MailAddress 字符串它。在 MailAddress 构造有一个构造函数,仅仅需要一个电子邮件字符串,或一个需要两个这样你就可以指定显示名称为好。

You can, however, Add a new MailAddress or string to it. The MailAddress constructor has a constructor that simply takes one email string, or one that takes two so you can specify a display name as well.

这篇关于C#中的ASP.NET转换为MailAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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