.pdf ファイルを電子メールに添付するためのコードについて助けが必要です。解決策を見つけようとしましたが、見つかりません。私の悪い英語でごめんなさい
これが私のpdf作成コードです
SaveFileDialog dialog1 = new SaveFileDialog();
dialog1.Title = "Saving pdf ";
dialog1.Filter = "PDF Files (*.pdf)|*.pdf|All files (*.*)|*.*";
dialog1.RestoreDirectory = true;
if (dialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dialog1.FileName);
}
/* DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string caminho = folderBrowserDialog1.SelectedPath;
var pasta2 = caminho.Replace(@"\", @"\\");*/
Document doc = new Document(PageSize.A4.Rotate(), 10, 10, 42, 35);
PdfWriter writertest = PdfWriter.GetInstance(doc, new FileStream(dialog1.FileName, FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(itemDataGridView.Columns.Count);
for (int j = 0; j < itemDataGridView.Columns.Count; j++)
{
table.AddCell(new Phrase(itemDataGridView.Columns[j].HeaderText));
}
table.HeaderRows = 1;
for (int i = 0; i < itemDataGridView.Rows.Count; i++)
{
for (int k = 0; k < itemDataGridView.Columns.Count; k++)
{
if (itemDataGridView[k, i].Value != null)
{
table.AddCell(new Phrase(itemDataGridView[k, i].Value.ToString()));
}
}
}
doc.Add(table);
doc.Close();
これが私のメール送信コードです
Pesquisar_Items pesquisar = new Pesquisar_Items();
var client = new SmtpClient("smtp.live.com", 25);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("josepedrobrito@hotmail.com", "*******");
var mail = new MailMessage();
mail.From = new MailAddress("josepedrobrito@hotmail.com");
mail.To.Add(textBox1.Text);
mail.IsBodyHtml = true;
mail.Subject = textBox2.Text;
string mailBody = "<table width='100%' style='border:Solid 1px Black;'>"; ;
foreach (DataGridViewRow row in itemDataGridView.Rows)
{
mailBody += "<tr>";
foreach (DataGridViewCell cell in row.Cells)
{
mailBody += "<td>" + cell.Value + "</td>";
}
mailBody += "</tr>";
}
mailBody += "</table>";
client.Send(mail);
MessageBox.Show("O email send ");
this.Close();