gpt4 book ai didi

c# - 将字符串格式化为电子邮件地址

转载 作者:行者123 更新时间:2023-11-30 18:19:07 25 4
gpt4 key购买 nike

此 SELECT 返回项目所有者的电子邮件地址:

var selectEmailData = "SELECT User.Email FROM Projects INNER JOIN User ON Projects.ProjectOwner = User.UserId WHERE ProjectId=@0";
var dataEmail = db.Query(selectEmailData, ProjectId);

@foreach (var row in dataEmail)
{
@row.Email
}

但是当我尝试这样做时:

var mailTo = dataEmail.ToString();

发送电子邮件:

WebMail.Send(
to: mailTo,
subject: "Hello there!",
body: "Your project is ready."
);

我明白了:指定的字符串不是电子邮件地址所需的格式。

这段代码有什么问题吗?

最佳答案

我很确定......

var dataEMail = db.Query(…) would return a collection not a string.

所以...

var mailTo = dataEmail.ToString();

会返回类似“System.Collections.Generic......”的内容

我猜你可能想要这样的东西

var selectEmailData = "SELECT User.Email FROM Projects INNER JOIN User  ON Projects.ProjectOwner = User.UserId WHERE ProjectId=@0";
var allEmails = db.Query(selectEmailData, ProjectId);

@foreach (var row in allEmails)
{
WebMail.Send(
to: @row.Email,
subject: "Hello there!",
body: "Your project is ready."
)

关于c# - 将字符串格式化为电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39712877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com