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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么