dousuitang5239 2019-07-26 22:59
浏览 256
已采纳

将换行符添加到base64url字符串

I have a program that is sending a base64url encoded string, but I read in places that the '\' character isn't supported by base64. My purpose is to send emails with the Gmail API in Go. The body part consists of the following:

"Name: 

This is the body of the email

Sincerely,
SenderName"

When I send emails through the Gmail API, I need to pass it a base64url string. I have the following function to handle that:

func encodeWeb64String(b []byte) string {

    s := base64.URLEncoding.EncodeToString(b)

    var i = len(s) - 1
    for s[i] == '=' {
        i--
    }

    return s[0 : i+1]
}

I have already added the header information to msg following this post, and have set the content type to text/html; charset=\"utf-8\". I then create the Gmail message using this:

gmsg := gmail.Message{
    Raw: encodeWeb64String([]byte(msg)),
}

When the email comes through, it looks like this:

Name: This is the body of the email Sincerely, SenderName

But I want each ' ' to put in actual newline. Thanks for any help, I am new with the Gmail API for Go.

  • 写回答

1条回答 默认 最新

  • dpmopn8542 2019-07-27 22:47
    关注

    I finally fixed it. I had to change the content type from text/html to text/plain, and now the newlines show properly on the email client

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作