Skip to content

How to parse string to mail.Address #2743

Open
@apuatcfbd

Description

@apuatcfbd

I am trying to parse the following

type NewEmail struct {
	From        mail.Address                 `form:"from"`
	// ...
}

with

// In handler
if err := c.Bind(dtoPtr); err != nil { // dtoPtr is *NewEmail
	errResponse = c.JSON(http.StatusBadRequest, Res(ResData{
		Msg: "Review your input",
		D:   err, // here's the error
	}))
	return
}

Getting following error unknown type

{
  "d": {
    "message": "unknown type"
  },
  "msg": "Review your input",
  "status": false
}

I've checked that it works if I make NewEmail structs From field to string from mail.Address. It is beneficial for me if I can parse to mail.Address based on my use case. How this can be done?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions