Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 是否将生成的PDF作为附件发送电子邮件?_Asp.net_Vb.net_Itextsharp_Html Email_Email Attachments - Fatal编程技术网

Asp.net 是否将生成的PDF作为附件发送电子邮件?

Asp.net 是否将生成的PDF作为附件发送电子邮件?,asp.net,vb.net,itextsharp,html-email,email-attachments,Asp.net,Vb.net,Itextsharp,Html Email,Email Attachments,我正在使用下面的代码生成PDF并将其保存到某个位置。是否可以将生成的PDF作为电子邮件发送出去?我假设电子邮件编码将需要在HTML中完成?因为它将位于Web服务器上。这可能吗 Dim Doc1 As New Document Dim path As String = "\\Server\Folder" + Session("Username") + "\" If (Not System.IO.Directory.Exists(path)) Then Sy

我正在使用下面的代码生成PDF并将其保存到某个位置。是否可以将生成的PDF作为电子邮件发送出去?我假设电子邮件编码将需要在HTML中完成?因为它将位于Web服务器上。这可能吗

    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()
试试这个:

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

' Set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")

' 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

您是否查看过
System.Net.Mail
名称空间?是的,但我不确定我将如何抓住那个附件?有些构造函数采用字符串,有些构造函数采用流。你应该能够找到一个适合你的。在下面的代码行中,我如何指向附件?说它是否在\\Server1\Attachments\上?Add(新附件(ms,“example.txt”,“text/plain”))