embed google qrcode in email

2019-09-09 19:31发布

问题:

I have a code that sends an email with embeded images using aspemail.

within the code i get a regular image by the <img> tag from google - so i get the qrcode

in the email, if the client does not download images automaticaly, he won't see the image

the embed of aspemail can't embed image/file that is not local

is there a way to save locally an image from a giving url?

if i get image from google: https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=http://www.sitedomain.com&choe=UTF-8

and have it saved as a unique name under specific folder

回答1:

Function SaveBinaryData(FileName, ByteArray)
  Const adTypeBinary = 1
  Const adSaveCreateOverWrite = 2

  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")

  BinaryStream.Type = adTypeBinary

  BinaryStream.Open
  BinaryStream.Write ByteArray

  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function

Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
' Point to an image file with adequate access permissions granted
objHTTP.open "GET", "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=http://www.domian.com&choe=UTF-8",false
objHTTP.send
'Response.BinaryWrite objHTTP.ResponseBody
call SaveBinaryData(Server.MapPath(".") & "\test.png", objHTTP.ResponseBody)
Set objHTTP = Nothing