【问题标题】:how can i send a canvas image using vb.net email如何使用 vb.net 电子邮件发送画布图像
【发布时间】:2012-05-25 03:05:47
【问题描述】:

我使用canvg将SVG转换为画布到图像,然后在vb.net客户端我将图像转换为bytearray()并将其保存到我的服务器上的文件夹中,以便我可以通过电子邮件附加:

 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)

我离做我想做的事还很远吗???

【问题讨论】:

    标签: c# asp.net vb.net html


    【解决方案1】:

    你正在尝试写作

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

    【讨论】:

    • 我需要内存流吗
    • @MinaGabriel:是的; Attachment 没有采用原始 byte[] 的构造函数。
    • 这会将字节数组作为未知文件类型发送,我需要先将字节数组转换为图像
    • @MinaGabriel:不;你只需要传递一个 MIME 类型作为第三个参数。
    • 我真的不知道该怎么做???如果您有一个很棒的链接或示例
    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 2010-12-24
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2014-10-18
    • 1970-01-01
    相关资源
    最近更新 更多