简体   繁体   中英

how can i send a canvas image using vb.net email

i convert a SVG to canvas using canvg to an image and then vb.net client side i convert the image to bytearray() and saved it to a folder on my server so i can attached by email :

 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

this code works fine and it send the image .

actually i don't need to save this image to my server i just wanted to send it without saving , this is what i have done so far

 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)

am i very far from doing what i want ???

您正在尝试写

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM