嗨,我想在一个wpf应用程序发送电子邮件,但我卡住了; 我显示我的xaml代码
<Grid>
<Button Style="{DynamicResource ShowcaseRedBtn}" CommandParameter="test@ygmail.com" Tag="Send Email" Content="Button" Height="23" HorizontalAlignment="Left" Margin="351,186,0,0" Name="button1" VerticalAlignment="Top" Width="140" Click="button1_Click" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="92,70,0,0" Name="txtSubject" VerticalAlignment="Top" Width="234" />
<TextBox AcceptsReturn="True" AcceptsTab="True" Height="159" HorizontalAlignment="Left" Margin="92,121,0,0" Name="txtBody" VerticalAlignment="Top" Width="234" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
在这里的代码背后:
private void button1_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
if (btn == null)
return;
string url = btn.CommandParameter as string;
if (String.IsNullOrEmpty(url))
return;
try
{
// here i wish set the parameters of email in this way
// 1. mailto = url;
// 2. subject = txtSubject.Text;
// 3. body = txtBody.Text;
Process.Start("mailto:test@gmail.com?subject=Software&body=test ");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Run Code Online (Sandbox Code Playgroud)
我的目的是设置电子邮件的参数绑定来自表单的数据:// 1. mailto = url; // 2. subject = txtSubject.Text; // 3. body = txtBody.Text;
你知道如何解决这一步吗?
非常感谢您的关注.
干杯
小智 11
您可以使用System.Net.MailMessage类直接发送邮件.请查看此类的MSDN文档中的以下示例:
public static void CreateTimeoutTestMessage(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server);
Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
client.Timeout = 100;
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try {
client.Send(message);
}
catch (Exception ex) {
Console.WriteLine("Exception caught in CreateTimeoutTestMessage(): {0}",
ex.ToString() );
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25774 次 |
| 最近记录: |