从web.config中的appsettings获取邮件ID

编程入门 行业动态 更新时间:2024-10-26 06:38:06
本文介绍了从web.config中的appsettings获取邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

<appSettings> <add key="fromemailid" value="development@relone"/> </appSettings>

代码隐藏我使用以下代码来获取frommailid

on codebehind i am using the following code to get frommailid

MailAddress from = new MailAddress(ConfigurationSettings.AppSettings("fromemailid"));

但是我得到了 非可调用成员''System.Configuration.ConfigurationSettings.AppSettings''不能像方法一样使用。 应该怎样我要克服这个错误....请帮助我。 在default.aspx.cs页面上

but iam getting "non-invocable member ''System.Configuration.ConfigurationSettings.AppSettings'' cannot used like a method". What should I do to overcome this error....Please help me. on default.aspx.cs page

if (conn.send_mail(tomailid))

Error 1 Member ''WorkflowSystem.DataAccess.connection1.send_mail(string)'' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\user\Desktop\WebApplication1\WebApplication1\Default.aspx.cs 73 25 WebApplication1

on connection.cs页面

on connection.cs page

public static bool send_mail(string toemailid) { MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].ToString()); }

Error 2 ''WorkflowSystem.DataAccess.connection1.send_mail(string)'': not all code paths return a value C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 110 28 WebApplication1

现在要做什么...请帮助我。

What is to be done now...Please help me.

推荐答案

你使用了错误的括号。 重写你的代码为 You are using wrong brackets. Rewrite your code as MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].toString());

1。 非可调用成员''System.Configuration.ConfigurationSettings.AppSettings''不能像方法一样使用 "non-invocable member ''System.Configuration.ConfigurationSettings.AppSettings'' cannot used like a method"

如下所示(由 @CodeMaster_Noob 建议)。

Do like below (as suggested by @CodeMaster_Noob).

MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].toString());

2.

2.

并非所有代码路径都返回值 "not all code paths return a value"

send_mail的方法签名是...

The method signature of "send_mail" is...

public static bool send_mail(string toemailid)

返回类型是bool无效。 但你还没有什么都归还了您应该根据您的逻辑返回 true 或 false 。 更新 版本-1 好​​的,做两件事。 1.更改功能签名。

where return type is "bool" not void. But you have not returned anything. You should return either true or false according to your logic. Update Version-1 Ok, so do two things. 1. Change function signature.

public static bool send_mail(string toemailid)

删除静态从这里开始。 所以,它将是...

Remove "static" from here. So, it will be...

public bool send_mail(string toemailid)

静态方法只能在自己的类中调用,而不能从其他类调用。 2.设置断点在这个函数中,看看当你发送邮件时是否执行此功能。 版本 - 2 1.

The static methods can only be called within its own class, not from other classes. 2. Put a break point in this function and see whether execution comes to this function, when you are sending mail. Version-2 1.

Quote:

错误2最佳重载方法匹配' 'System.Net.Mail.MailMessage.MailMessage(System.Net.Mail.MailAddress,System.Net.Mail.MailAddress)''有一些invali d参数C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 114 30 WebApplication1 错误3参数2:无法从''string''转换为' 'System.Net.Mail.MailAddress''C:\ Users \ user \Desktop\WebApplication1 \WebApplication1 \connection.cs 114 52 WebApplication1

Error 2 The best overloaded method match for ''System.Net.Mail.MailMessage.MailMessage(System.Net.Mail.MailAddress, System.Net.Mail.MailAddress)'' has some invalid arguments C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 114 30 WebApplication1 Error 3 Argument 2: cannot convert from ''string'' to ''System.Net.Mail.MailAddress'' C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 114 52 WebApplication1

写完之后下面

After writing like below

MailMessage mm = new MailMessage(from, to);

上述错误将被修复。 as MailMessage类有如下构造函数......(你可以看到那里) 1. MailMessage构造函数(MailAddress,MailAddress) 你应该传递两个MailAddress对象。 2. MailMessage构造函数(字符串,字符串) 你应该传递两个字符串。 3. MailMessage构造函数(String,String,String,String) 你应该传递四个字符串。 - > 以前,你已写过......

the above errors will be fixed. As MailMessage Class has constructors like below...(you can see there) 1. MailMessage Constructor (MailAddress, MailAddress) where you should pass two MailAddress objects. 2. MailMessage Constructor (String, String) where you should pass two strings. 3. MailMessage Constructor (String, String, String, String) where you should pass four string. -> Previously, you have written...

MailMessage mm = new MailMessage(from, toemailid);

其中来自是 MailAddress 类,但 toemailid 是一个字符串。 - > 现在你已经完成了正确的...

where from is a object of MailAddress Class, but toemailid was a string. -> Now you have done correct like...

MailMessage mm = new MailMessage(from, to);

其中来自和到是 MailAddress 类的对象。 谢谢......

where both from and to are objects of MailAddress Class. Thanks...

更多推荐

从web.config中的appsettings获取邮件ID

本文发布于:2023-11-09 06:16:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571603.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮件   config   web   ID   appsettings

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!