2014-04-04 21 views
5

Tôi đang sử dụng tạo một Ứng dụng Cửa hàng Windows 8.1 trong WinRT.Không thể tạo thư mới có nhiều người nhận với mailto uri

Tôi không thể tạo thư mới với nhiều người nhận bằng url thư đến bằng cách tách từng email bằng dấu phẩy hoặc dấu hai chấm, cả hai đều cho tôi lỗi giống nhau.

Invalid URI: The hostname could not be parsed. 

mailto chuỗi trông như thế này

"mailto:[email protected],[email protected]" 
"mailto:[email protected],[email protected]," 
"mailto:[email protected], [email protected]" 
"mailto:[email protected];[email protected]" 
"mailto:[email protected];[email protected];" 
"mailto:[email protected]; [email protected]" 

Tôi đã thử tất cả các biến thể một bài cho tôi những lỗi tương tự khi newing lên uri, như thế này.

var uri = new Uri(string.Format("mailto:{0}", mails)); 

Tôi không có ý tưởng những gì tôi đang làm sai, hoặc trong trường hợp nó không được thực hiện do tại sao nó sẽ không được?

Tôi tạo ra một vài đơn vị xét nghiệm để xem nếu có sự thay đổi sẽ làm việc, nhưng không có ..

[TestClass] 
public class UriMailToTest 
{ 
    private Uri CreateMailToUri(string mail) 
    { 
     if (string.IsNullOrEmpty(mail)) throw new ArgumentNullException("mail"); 

     var uriMailTo = string.Format("mailto:{0}", mail); 
     return new Uri(uriMailTo); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest1() 
    { 
     const string mailto = "[email protected]"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest2() 
    { 
     const string mailto = "[email protected],userna[email protected]"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest3() 
    { 
     const string mailto = "[email protected],[email protected],"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest4() 
    { 
     const string mailto = "[email protected];[email protected]"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest5() 
    { 
     const string mailto = "[email protected];[email protected];"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest6() 
    { 
     const string mailto = "[email protected], [email protected]"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest7() 
    { 
     const string mailto = "[email protected]; [email protected]"; 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest8() 
    { 
     var mails = new[] { "[email protected]", "[email protected]"}; 
     var mailto = mails.Select(WebUtility.UrlEncode).Aggregate((c, n) => string.Format("{0},{1}", c, n)); 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest9() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Select(WebUtility.UrlEncode).Aggregate((c, n) => string.Format("{0};{1}", c, n)); 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest10() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Aggregate((c, n) => string.Format("{0},{1}", c, n)); 
     var urlEncodedMailTo = WebUtility.UrlEncode(mailto); 
     var uri = CreateMailToUri(urlEncodedMailTo); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest11() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Aggregate((c, n) => string.Format("{0};{1}", c, n)); 
     var urlEncodedMailTo = WebUtility.UrlEncode(mailto); 
     var uri = CreateMailToUri(urlEncodedMailTo); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest12() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Select(WebUtility.UrlEncode).Aggregate((c, n) => string.Format("{0}, {1}", c, n)); 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest13() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Select(WebUtility.UrlEncode).Aggregate((c, n) => string.Format("{0}; {1}", c, n)); 
     var uri = CreateMailToUri(mailto); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest14() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Aggregate((c, n) => string.Format("{0}, {1}", c, n)); 
     var urlEncodedMailTo = WebUtility.UrlEncode(mailto); 
     var uri = CreateMailToUri(urlEncodedMailTo); 
     uri.Should().NotBeNull(); 
    } 

    [TestMethod] 
    public void CreateMailToUriTest15() 
    { 
     var mails = new[] { "[email protected]", "[email protected]" }; 
     var mailto = mails.Aggregate((c, n) => string.Format("{0}; {1}", c, n)); 
     var urlEncodedMailTo = WebUtility.UrlEncode(mailto); 
     var uri = CreateMailToUri(urlEncodedMailTo); 
     uri.Should().NotBeNull(); 
    } 
} 

với Windows Key + R (Run) gõ vào mailto: [email protected]; USERNAME2 @ mail.com hoạt động tuyệt vời, tôi chỉ không thể tạo đối tượng Uri với nhiều người nhận ...

Theo mailto:Protocol @ msdn tôi sẽ có thể sử dụng giao thức mailto với nhiều người nhận.

Cú pháp

mailto: sAddress [sHeaders]

Tokens

sAddress 
    One or more valid e-mail addresses separated by a semicolon. You must use Internet-safe characters, such as %20 for the space character. 
sHeaders 
    Optional. One or more name-value pairs. The first pair should be prefixed by a "?" and any additional pairs should be prefixed by a "&". The name can be one of the following strings. 
subject 
    Text to appear in the subject line of the message. 
body 
    Text to appear in the body of the message. 
CC 
    Addresses to be included in the "cc" (carbon copy) section of the message. 
BCC 
    Addresses to be included in the "bcc" (blind carbon copy) section of the message. 
+0

Bạn có thể thử với ' mailto: [email protected]? [email protected]; username3 @ mail.com'? – ohaal

+0

điều thú vị là công trình @ohaal nhưng 'mailto:? [email protected]; username2 @ mail.com' không hoạt động. – furier

+0

Như một cách giải quyết dơ bẩn, bẩn thỉu, cách tạo một trang web tải trong nền và mở 'mailto:' từ đó? Một cái gì đó dọc theo dòng của ' ' – ohaal

Trả lời

-4
cant you follow this code? 

    System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(); 

    email.To.Add("[email protected]"); 
    email.CC.add("[email protected]l.com"); 
    email.CC.add("[email protected]"); 
    email.CC.add("[email protected]"); 
+3

Bạn có thể giải thích tại sao đây là một giải pháp tốt cho vấn đề. –

+0

Điều này làm việc nhưng không phải là giải pháp của nó và nó là một cách giải quyết rất xấu. – furier

2

Có một hack, sử dụng HyperLinkButton (sor ry, đây là một bẩn hack):

  1. tải một hyperlinkbutton sử dụng một XAmlReader,
  2. Lấy nó AutomationPeer,
  3. Launch một nhấp chuột

    var uriString = "mailto:[email protected],[email protected]"; 
        string xamlString = "<HyperlinkButton " 
        + "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " 
        + "NavigateUri=\"" + uriString + "\"/>"; 
        var c = (HyperlinkButton)XamlReader.Load(xamlString); 
        new HyperlinkButtonAutomationPeer(c).Invoke(); 
    
Các vấn đề liên quan