C# Windows Form Application - Send email using gmail smtp

前端 未结 2 479
梦如初夏
梦如初夏 2021-02-03 13:45

I have been trying to create a small program to send email through smtp.gmail.com, but it always prompt me that \"The operation has timed out\". I know there are lots of soluti

2条回答
  •  萌比男神i
    2021-02-03 14:27

    how to how to send email of pdf file which is store in d drive in c# windows application...the answer is...

    MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress(txtFrom.Text.ToString());
                mail.To.Add(txtmailTo.Text.ToString());
                mail.Subject = "Mail Pdf";
                var filename = @"D:/your file path/.pdf";
                mail.Attachments.Add(new Attachment(filename));
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new 
                System.Net.NetworkCredential(txtFrom.Text, txtPassword.Text);
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
    

提交回复
热议问题