отправка информации с вложением на адрес электронной почты наиболее конкретно с помощью Google - PullRequest
0 голосов
/ 11 января 2020

Я хочу отправить электронное письмо с вложенным файлом при нажатии кнопки, но оно показывает «сбой отправки почты», даже когда я подключен к Интернету, я все еще не могу понять, в чем проблема

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

1 Ответ

1 голос
/ 11 января 2020
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!")
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...