go - go-ole 在 html 电子邮件中嵌入图像
问题描述
我正在尝试将图像添加到电子邮件正文。首先,我尝试传递给 base64,它可以工作,但取决于您发送到的域,他们看不到它们。所以我正在尝试使用以下代码。我必须使用 Outlook 发送邮件,因为如果不是通过 Outlook,它不允许我访问服务器。
func send(html, asunto string, archivos []string, para, copia string) error {
fmt.Println("Enviando correo")
ole.CoInitialize(0)
unknown, err := oleutil.CreateObject("Outlook.Application")
if err != nil {
log.Print(err)
return err
}
outlook, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
log.Print(err)
return err
}
newmail := oleutil.MustCallMethod(outlook, "CreateItem", "0").ToIDispatch()
if asunto != "" {
oleutil.MustPutProperty(newmail, "Subject", asunto)
}
if para != "" {
oleutil.MustPutProperty(newmail, "To", para)
}
if copia != "" {
oleutil.MustPutProperty(newmail, "CC", copia)
}
if html != "" {
oleutil.MustPutProperty(newmail, "HTMLBody", html)
}
for _, archivo := range archivos {
if _, err := os.Stat(archivo); os.IsNotExist(err) {
fmt.Printf("No se ha podido añadir el archivo%s\n", archivo)
continue
}
newAtt := oleutil.MustGetProperty(newmail, "Attachments").ToIDispatch()
if strings.HasSuffix(strings.ToLower(archivo), ".png") {
property := oleutil.MustCallMethod(newAtt, "Add", archivo).ToIDispatch()
// Here I have tried to set several properties to see if any of them work but I get an error.
// oleutil.MustPutProperty(property, "ContentId", archivo)
// oleutil.MustPutProperty(property, "http://schemas.microsoft.com/mapi/proptag/0x3712001F", archivo)
} else {
oleutil.MustCallMethod(newAtt, "Add", archivo)
}
}
oleutil.MustCallMethod(newmail, "Send").ToIDispatch()
fmt.Println("Correo enviado")
}
我添加以下html
const html = `<p>Bolsa en curso Instalaciones:</p>
<img src="cid:%s" alt="foto Bola en curso Instalaciones">
解决方案
推荐阅读
- c++ - 如何在 C++ 编译时创建成员变量的集合?
- python - 尝试在 Jupyter Notebook 中导入 sklearn 时出错
- blockchain - Chain Link VRF 需要很长时间才能获得随机数
- oracle - PBI - 直接查询和 Oracle 表功能
- amazon-web-services - 来自 S3 的 URL 图像不显示图像
- r - 如何以时间单位将时间序列数据绘制为箱线图?
- kibana - 如何在 Kibana、Grafana 等任何工具中为磁盘中的结构化日志文件创建仪表板
- android - 自定义布局不会改变其相对于其他元素的位置
- javascript - JavaScript 表格未显示在屏幕上
- python - 使用 BeatifulSoup 类 == 解析 HTML 并且标题包含