我显示我的xaml代码
<GrID> <button Style="{DynamicResource ShowcaseRedBtn}" CommandParameter="test@ygmail.com" Tag="Send Email" Content="button" Height="23" HorizontalAlignment="left" margin="351,186,0" name="button1" VerticalAlignment="top" WIDth="140" Click="button1_Click" /> <TextBox Height="23" HorizontalAlignment="left" margin="92,70,0" name="txtSubject" VerticalAlignment="top" WIDth="234" /> <TextBox AcceptsReturn="True" AcceptsTab="True" Height="159" HorizontalAlignment="left" margin="92,121,0" name="txtbody" VerticalAlignment="top" WIDth="234" /></GrID>
在这里的代码背后:
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); } }
我的目的是设置电子邮件的参数绑定表单中的数据:
// 1. mailto = url;
// 2. subject = txtSubject.Text;
// 3. body = txtbody.Text;
你知道如何解决这一步吗?
非常感谢您的关注.
干杯
解决方法 您可以使用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() ); } }总结
以上是内存溢出为你收集整理的c# – 使用wpf发送电子邮件全部内容,希望文章能够帮你解决c# – 使用wpf发送电子邮件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)