2012-05-24 43 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我需要将字节阵列转换为图像第一个权利 –

相关问题