我想用C#發送帶有郵件的pdf文件。我知道我可以發送郵件,但我不知道我怎麼能發送郵件用PDF文件:(如何用PDF文件發送郵件
比如我在文件夾C PDF文件:\檢驗.pdf
這裏是我的代碼:
private void SendEmail(string pdfpath,string firstname, string lastname, string title, string company, string mailfrom,string mailto)
{
try
{
MailMessage m = new MailMessage();
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
m.From = new System.Net.Mail.MailAddress(mailfrom);
m.To.Add(mailto);
m.Subject = "Company Gastzugang (" + lastname + ", " + firstname + ")";
// what I must do for sending a pdf with this email
m.Body = "Gastzugangdaten sind im Anhang enthalten";
sc.Host = SMTPSERVER; // here is the smt path
sc.Send(m);
}
catch (Exception ex)
{
error.Visible = true;
lblErrorMessage.Text = "Folgender Fehler ist aufgetreten: " + ex.Message;
}
}
你需要它作爲附件? – ryadavilli