2013-07-19 2 views
0

아래 코드를 사용하여 PDF를 생성하고 위치에 저장합니다. 생성 된 PDF가 첨부 된 이메일로 보낼 수 있습니까? 전자 메일 코딩이 HTML로 수행되어야한다고 가정합니다. 그것은 웹 서버에 있기 때문입니다. 이것이 가능한가?생성 된 PDF를 전자 메일로 첨부 파일로 보내시겠습니까?

Dim Doc1 As New Document 
    Dim path As String = "\\Server\Folder" + Session("Username") + "\" 
    If (Not System.IO.Directory.Exists(path)) Then 

     System.IO.Directory.CreateDirectory(path) 
    End If 
    Dim myUniqueFileName = String.Format("{0}.pdf", random) 
    Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(Doc1, New FileStream(path & myUniqueFileName, FileMode.Create)) 
    ' Dim ev As New itsEvents 
    ' pdfWrite.PageEvent = ev 

    Doc1.Open() 
    Dim test As String 
    test = Session("PDF") 
    Dim imagepath As String = Server.MapPath(".") & "/images/Header.png" 
    Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imagepath) 
    image.ScalePercent(70.0F) 
    ' image.SetAbsolutePosition(36.0F, 36.0F) 
    Doc1.Add(image) 
    Doc1.Add(New Paragraph(test)) 

    Doc1.Close() 
+1

당신이'System.Net.Mail' 네임 스페이스에 봤어? http://msdn.microsoft.com/en-us/library/System.Net.Mail.aspx –

+0

예,하지만 첨부 파일을 어떻게 가져올 지 모르겠습니다. – user1342164

+0

http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx 문자열을 사용하는 생성자와 스트림을 사용하는 생성자가 있습니다. 당신은 당신을 위해 일하는 것을 찾을 수 있어야합니다. –

답변

0

이 시도 :

' Create the mail message 
Dim mail As New MailMessage() 

' Set the addresses 
mail.From = New MailAddress("[email protected]") 
mail.To.Add("[email protected]") 

' Set the content 
mail.Subject = "This is an email" 
mail.Body = "this content is in the body" 

' Get some binary data 
Dim data As Byte() = GetData() 

' Save the data to a memory stream 
Dim ms As New MemoryStream(data) 

' Create the attachment from a stream. Be sure to name the data with a file and 
' media type that is respective of the data 
mail.Attachments.Add(New Attachment(ms, "example.txt", "text/plain")) 

' Send the message 
Dim smtp As New SmtpClient("127.0.0.1") 
smtp.Send(mail) 

Function GetData() As Byte() 
    ' This is where you will load your data from disk or database, etc. 
    Dim s As String = "this is some text" 
    Dim data As Byte() = Encoding.ASCII.GetBytes(s) 
    Return data 
End Function 'GetData 
+0

다음 코드 줄에서 첨부 파일을 어떻게 가리 킵니까? 만약 그것의 \\ Server1 \ Attachments \에? mail.Attachments.Add (새 첨부 파일 (ms, "example.txt", "text/plain")) – user1342164

관련 문제