2014-02-17 68 views
1

在我的Windows Phone 7應用程序中,我想發送一封電子郵件,其中郵件正文應該包含我的應用程序中上一頁的數據。以前我只是集成了電子郵件工具是這樣的:從Windows Phone 7應用程序發送電子郵件

private void Image_Email(object sender, RoutedEventArgs e) 
{ 
    EmailComposeTask emailComposeTask = new EmailComposeTask(); 

    emailComposeTask.Subject = "message subject"; 
    emailComposeTask.Body = "message body"; 
    emailComposeTask.To = "[email protected]"; 
    emailComposeTask.Cc = "[email protected]"; 
    emailComposeTask.Bcc = "[email protected]"; 
    emailComposeTask.Show(); 
} 

但我不能在我的模擬器來測試這一點。現在在body部分我想要我的數據來自上一頁。那麼如何做到這一點?

更新代碼:

if (this.NavigationContext.QueryString.ContainsKey("Date_Start")) 
{ 
    //if it is available, get parameter value 
    date = NavigationContext.QueryString["Date_Start"]; 
    datee.Text = date; 
} 

if (this.NavigationContext.QueryString.ContainsKey("News_Title")) 
{ 
    //if it is available, get parameter value 
    ntitle = NavigationContext.QueryString["News_Title"]; 
    title.Text = ntitle; 
} 

if (this.NavigationContext.QueryString.ContainsKey("News_Description")) 
{ 
    ndes = NavigationContext.QueryString["News_Description"]; 
    description.Text = ndes; 
} 

現在應該做些什麼在郵件正文中寫?我無法測試它,因爲我沒有設備。 我可以通過在這樣的價值觀:

emailComposeTask.Body = "title, ndes, date"; 

回答

1

我覺得代碼是正確的。如果你想從前一頁傳遞正文,則需要在頁面導航時傳遞它。並設置emailComposeTask.Body = yourPassedValue。 這樣的:

var date; 
var title; 
var ndes; 

emailComposeTask.Body = title + "," + ndes + "," + date; 
+0

請參閱我的更新代碼。這是寫它的方式嗎? – bhaku

+0

看到我更新的代碼。 –

+0

嗨,@ bhaku,你有沒有讀過代碼?有什麼問題嗎? –

1

你需要編輯郵件正文一行:

emailComposeTask.Body = title+" "+ ndes+" "+ date; 
1

你不能在模擬器中測試發送郵件,因爲你沒有一個正確的電子郵件帳戶設置做。你也不能在模擬器中設置它。

Body屬性是一個字符串,所以你可以放在裏面幾乎任何你想要的東西。

使用下面的代碼將只生成包含正是一個字符串:

emailComposeTask.Body = "title, ndes, date"; 

所以結果郵件將包含「稱號,瀕死體驗,日期」作爲文本的主體。如果要用名稱爲title的本地變量中的值替換標題,則需要使用以下語法:

emailComposeTask.Body = string.Format("{0}, {1}, {2}", title, nodes, date); 
相關問題