ここで私の問題です。サーバ上の一時フォルダに保存されているPDFファイルを生成するWebページ(既存のプロジェクトに属していない外部Webページ)を生成しました。指定されたパラメータでPDFが生成されます。 私はそのウェブページがどのようなものであれ(PDF)を保存し、それを電子メールに添付して、結果が---->電子メールにPDFを添付したいと思っています。PDFをダウンロードして電子メールに添付する
Dim FullReportUrl As String = Nothing
FullReportUrl = (String.Format("https://www.something.com/Reports/ReportManager.aspx?SessionID={0}&report=CaseFullReport&CompanyCode={1}&ExportType=pdf&ConnectionType=Main&GlobalVar=IncidentID^{2}|CompanyCode^{3}", "2c3fe87f-5c4e-4a7d-acda-970ed47f27eb", m_User.CompanyCode, m_IncidentCaseID.ToString(), m_User.CompanyCode))
'# Create mail message
Dim msg As New MailMessage
msg.From = New MailAddress(Globals.gFromEmailAddr)
msg.To.Add(New MailAddress("[email protected]"))
msg.Subject = String.Concat("Full Report IR-", m_IncidentID.ToString())
'# Attach the additional text to the E-Mail.
If Not String.IsNullOrEmpty(rtbAdditionalText.Text.ToString()) Then
msg.Body = "<html><body>Dear " + "Test" + ", (Please Do Not Replay to this email)<br><br>" + rtbAdditionalText.Text.ToString().Trim() + "<br><br> Sincerely,<br> Something." + "<br><img id=""Logo"" alt=""logo"" src=""https://www.something.com/gs/Images/Layout/logo.png""/></body></html>"
End If
msg.IsBodyHtml = True
msg.Priority = MailPriority.High
'# Attach the full report to the email.
Dim ms As MemoryStream = New MemoryStream
Dim writer As StreamWriter = New StreamWriter(ms)
With writer
.Write(GetFileStream(FullReportUrl))
.Flush()
'ms.Position = 0 '== Reading the stream from the beginging and finializing it.
Dim attach As Attachment = New Attachment(ms, "test.pdf", System.Net.Mime.MediaTypeNames.Application.Pdf)
msg.Attachments.Add(attach)
End With
'Create client and send
Dim client As New SmtpClient(Globals.gMailServer)
client.Credentials = New System.Net.NetworkCredential("[email protected]", "555555$")
Dim userState As Object = msg
client.Send(msg)
msg = Nothing
client.Dispose()
破損出てくるPDF。なぜ誰かが指摘できますか?
投稿されたコードはVB.NETですが、C#とVB.NETの両方であなたの質問にタグを付けました。あなたはどれが欲しいですか?あなたは 'FullReportUrl'で何をしていますか?レポートURLはPDFを返すものですか? – Tim
FullReportURL - PDFファイルを生成するURL。 – user3188868