.NET 中的 MailTo URI 对象?
给定一个 URI(已确认为 Uri.UriSchemeMailto
),是否有一个可以转换为提供 mailto 属性的对象?
就像 .TargetURI
是 {mailto:[email ;protected]?subject=我全部完成&body=完成&[电子邮件受保护]&[电子邮件受保护]}< /strong> 是否有一个对象会将其作为 URI 并返回 MailTo 属性?就像
伪代码
Dim mailDetails as New MailDetailsObject(MyURI.TargetURI)
Console.WriteLine(mailDetails.To)
Console.WriteLine(mailDetails.CC)
Console.WriteLine(mailDetails.BCC)
Console.WriteLine(mailDetails.Subject)
Console.WriteLine(mailDetails.Body)
一样,结果是:
[email protected] [email protected] [email protected] I'm all done Finished
或者这是人们通常只是手动解析或构造 .TargetURI
下的属性?
Given a URI (that is confirmed to be a Uri.UriSchemeMailto
) is there an object this can be cast to that would give provide mailto properties?
Like if the .TargetURI
was {mailto:[email protected]?subject=I'm all done&body=Finished&[email protected]&[email protected]} is there an object that will take this as a URI and spit back MailTo properties? Like
Pseudo Code
Dim mailDetails as New MailDetailsObject(MyURI.TargetURI)
Console.WriteLine(mailDetails.To)
Console.WriteLine(mailDetails.CC)
Console.WriteLine(mailDetails.BCC)
Console.WriteLine(mailDetails.Subject)
Console.WriteLine(mailDetails.Body)
That results in:
[email protected] [email protected] [email protected] I'm all done Finished
Or is this something people normally just manually parse or construct out of the properties under .TargetURI
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有一个类可以做到这一点,但您可以使用
HttpUtility.ParseQueryString()
方法:I don't know of a class that does that, but you could easily extract it with the
HttpUtility.ParseQueryString()
method:我最终为此编写了自己的课程。它并不完整,也没有使用模式的所有可能部分对其进行测试,但它似乎对于大多数 mailtos 来说工作得足够好。请随意编辑此答案并进行改进。
请注意,将
.TargetURI
传递到构造函数中可能会导致失败,因为它似乎没有覆盖完整的架构。例如mailto:[电子邮件受保护],< a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afc5c6c2efc5c0c7c181ccc0c2">[电子邮件受保护](两个收件人)将导致.TargetURI
失败。在这种情况下,您可以改为传入.TargetURI.OriginalString
。I ended up writing my own class for this. It's not complete and haven't tested it with all possible parts of the schema, but it appears to work well enough for most mailtos. Feel free to edit this answer with improvements.
Note that passing a
.TargetURI
into the constructor may cause failures as it doesn't appear to cover the full schema. For example mailto:[email protected],[email protected] (two recipients) will cause.TargetURI
to fail. In that case, you can pass in.TargetURI.OriginalString
instead.