Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将带有附件的信息发送到电子邮件地址,这在google中最为常见_C#_Wpf_Email - Fatal编程技术网

C# 将带有附件的信息发送到电子邮件地址,这在google中最为常见

C# 将带有附件的信息发送到电子邮件地址,这在google中最为常见,c#,wpf,email,C#,Wpf,Email,我想在点击按钮时发送一封带有附件的电子邮件,但即使在 我已经上网了 我还是不知道问题出在哪里 private void proto_Type_AI_(object sender, RoutedEventArgs e) { try { //Smpt Client Details SmtpClient clien

我想在点击按钮时发送一封带有附件的电子邮件,但即使在 我已经上网了 我还是不知道问题出在哪里

private void proto_Type_AI_(object sender, RoutedEventArgs e)
        {           
            try
            {
                //Smpt Client Details                    
                SmtpClient clientDetails = new SmtpClient();
                clientDetails.Port = Convert.ToInt32(port_number.Text.Trim());
                clientDetails.Host = smtp_server.Text.Trim();
                clientDetails.EnableSsl = ssl.IsChecked == true;
                clientDetails.DeliveryMethod = SmtpDeliveryMethod.Network;
                clientDetails.UseDefaultCredentials = false;
                clientDetails.Credentials = new NetworkCredential(sender_email.Text.Trim(), sender_password.Password.Trim());

                //message details
                MailMessage maildetails = new MailMessage();
                maildetails.From = new MailAddress(sender_email.Text.Trim());
                maildetails.To.Add(recipent_email.Text.Trim());
                //maildetails.Bcc.Add("bcc email address");
                maildetails.Subject = subject.Text.Trim();
                maildetails.IsBodyHtml = html.IsChecked == true;
                maildetails.Body = body.Text.Trim();               

                clientDetails.Send(maildetails);

                MessageBox.Show("HEY USER, YOUR MESSAGE HAS BEEN SENT");

            }
            catch (Exception ex)
            {[![enter image description here][1]][1]
                MessageBox.Show(ex.Message);
            }
        }
以下是输出图片
我正在使用google smtp发送它

如果您使用的是Windows和MS Outlook,您可以使用Nuget软件包管理器为该任务添加库microsoft.office.interop.Outlook,并在类中实现它:
using Microsoft.Office.Interop.Outlook; 

namespace YourNamespace
{
   public class YourClass
   { 
    //Create a mail object 
    Microsoft.Office.Interop.Outlook.Application ol = new  Microsoft.Office.Interop.Outlook.Application(); 
    //Create a mail item 
    Microsoft.Office.Interop.Outlook.MailItem mailitem = ol.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 
    //Your mail subject text 
    mailitem.Subject = "SMART G's Auto Email Test"; 
    //Mail Recipient 
    mailitem.To = "smartg@smartg.com"; 
    //Mail Sub Recipient 
    mailitem.CC = "test@test.com"; 
    //Your E-Mail Text 
    mailitem.Body = "Dear Sir or Madam,\n\n" + 
   "Attached please find my great manual on how to save the world. Thank you for reading. + "\n\n"
    + "Kind regards" + "\n\n" + "Smart G"; 
    //Your mail attachment
    mailitem.Attachments.Add(<<path>> + <<documentName>>); 
    //Do you want me to show you the mail?                           
    mailitem.Display(true); //yes 
    //If you want to check the mail before sending it then do not use this.     
    mailitem.Send(); //automatically sends the mail before you can check it! (autosend) 
    //Notifcation 
    MessageBox.Show("Mail sent!")
    }
}