MailAddress字符串格式 [英] MailAddress string format

查看:120
本文介绍了MailAddress字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我将电子邮件功能放入我使用C#制作的网络应用程序中。我很难找到正确格式的电子邮件

地址。我想在字符串中放置多个地址,但是

我尝试的一切都不起作用。

这是我的代码:

protected void SendEmail_Click (对象发送者,EventArgs e)

{

string emailSubject =" Test Subject" ;;

string emailTo =" emailaddress1; emailaddress2" ;

string emailFrom =" emailaddress";

string emailBody =" Test Email";

string SMTPServer =" localhost" ;;


this.SendReminderEmail(this.Context,emailSubject,emailTo,

emailFrom,emailBody,SMTPServer);

}


显然我会替换emailaddress1有了一个真实的电子邮件地址,我只是出于安全原因而忽略了电子邮件地址。我试过

没有空格分号,分号有空格,逗号没有

空格,逗号有空格,可以分割电子邮件地址。没有什么

有效。

谢谢。

Greg

Hello,
I am putting email function into a web app I am making using C#. I am
struggling to find out the proper format for the string of To email
addresses. I want to put multiple addresses in the string, but
everything I try does not work.
Here is my code:
protected void SendEmail_Click(object sender, EventArgs e)
{
string emailSubject = "Test Subject";
string emailTo = "emailaddress1;emailaddress2";
string emailFrom = "emailaddress";
string emailBody = "Test Email";
string SMTPServer = "localhost";

this.SendReminderEmail(this.Context, emailSubject, emailTo,
emailFrom, emailBody, SMTPServer);
}

Obviously I will replace "emailaddress1" with a real email address, I
just left out the email addresses for security reasons. I have tried
putting semicolon with no space, semicolon with a space, comma with no
space, and comma with a space, to divide the email addresses. Nothing
works.
Thanks.
Greg

推荐答案

什么不起作用?你得到一个错误,它只向其中一个发送

,还是根本不发送?

What is it that isn''t working? Do you get an error, does it only send
to one or the other, or does it not send at all?


这是我得到的错误:


指定的字符串不是电子邮件地址所需的格式。


我只是我试图找到在代码中插入多个电子邮件

地址的正确格式。当管理员点击一个按钮时,它应该发送一封电子邮件。
。当我在那里有一个

的电子邮件地址时它工作正常,但是当我尝试放置多个时,它确实没有工作。我认为必须有一种方法可以做多个电子邮件

地址,我只是不能正确的格式。

谢谢

This is the error I get:

The specified string is not in the form required for an e-mail address.

I just am trying to find the proper format for inserting multiple email
addresses in the code. When the administrator clicks a button, it is
supposed to send out an email. It works just fine when I have one
email address in there, but when I try to put more than one, it does
not work. I figure there has to be a way to do more than one email
address, I just can''t get the format right.
Thanks


System.Net.MailMessage类有一个To属性,它是一个

的MailAddresses集合(MailAddressCollection)。要向多个收件人发送电子邮件

,您必须将MailAddress添加到该

集合中。以下是一些示例代码:


MailMessage msg = new MailMessage();

msg.To.Add(new MailAddress(&em; em ****) @ test.com"));

msg.To.Add(新邮件地址(&em; em **** @ test.com"));

.. ...

.....


显然这必须在你的SendReminderEmail

方法中编程。你可以做的是让emailTo参数成为一个数组

的蜇然后你的方法在这个字符串数组上做一个foreach,然后将地址添加到我上面展示的收藏品。


我希望这有帮助

The System.Net.MailMessage class has a To property which is a
collection of MailAddresses ( MailAddressCollection). To send an email
to multiple recipients you have to add a MailAddress to that
collection. Here is some sample code:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("em****@test.com"));
msg.To.Add(new MailAddress("em****@test.com"));
.....
.....

Obviously this would have to be programed in your SendReminderEmail
method. What you can do is have the emailTo parameter to be an array
of stings and then inside your method do a foreach on this string array
and then add the address to the collection like I shown above.

I hope this helps


这篇关于MailAddress字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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