2012-05-24 75 views
0

我轉換SVG到畫布使用Canvg的圖像,然後vb.net客戶端我將圖像轉換爲bytearray()並將其保存到我的服務器上的文件夾所以我可以通過電子郵件附加:我怎樣才能發送一個畫布圖像使用vb.net電子郵件

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 
    Dim path = Server.MapPath("PDFs\") 
    Dim fileNameWithPath As String = path + DateTime.Now.ToString().Replace("/", "-").Replace(" ", "-").Replace(":", "") + ".jpeg" 
    Dim fs As FileStream = New FileStream(fileNameWithPath, FileMode.Create) 
    Dim bw As BinaryWriter = New BinaryWriter(fs) 
    Dim ByteArray() As Byte = Convert.FromBase64String(hfChartImg.Value) 
    bw.Write(ByteArray) 
    bw.Close() 

    Dim file As String = fileNameWithPath 
    Dim message As New MailMessage() 
    message.From = New MailAddress("****************") 
    message.To.Add(New MailAddress("***************")) 
    message.Subject = "new image " 
    message.Body = "this is the apak chart img" 
    Dim data As New Attachment(file) 
    message.Attachments.Add(data) 
    Dim client As New SmtpClient() 
    client.Host = "smtp.gmail.com" 
    client.Credentials = New NetworkCredential("***************", "*******") 
    client.EnableSsl = True 
    client.Port = 587 
    client.Send(message) 
End Sub 

此代碼工作正常,它發送圖像。

其實我並不需要保存這個圖像到我的服務器我只是想送它不保存,這是我迄今所做

Protected Sub emailSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles emailSend.Click 
    Dim customerChoice As String = DropDownList1.Text 
    Select Case customerChoice 
     Case "pdf" 
      MsgBox("select pdf ") 
     Case "image" 
      Dim imageFile As MemoryStream = New MemoryStream() 
      Dim bw As BinaryWriter = New BinaryWriter(imageFile) 
      Dim bytearray() As Byte = Convert.FromBase64String(hfChartImg.Value) 
      bw.Write(bytearray) 

我是從做很遠,我想要什麼???

回答

0

你試圖寫

Dim data As New Attachment(New MemoryStream(ByteArray), "SomeName") 
+0

我需要在所有 –

+0

@MinaGabriel一個MemoryStream:是的; 'Attachment'沒有一個構造函數,它需要一個原始的'byte []'。 – SLaks

+0

這將發送字節陣列作爲未知文件類型i thisnk我需要將字節陣列轉換爲圖像第一個權利 –

相關問題