Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6a33647f
authored
2014-10-10 23:40:02 +0800
by
TossPig
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改参数类型
为了保持向后兼容,
1 parent
e5134873
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
utils/mail.go
utils/mail.go
View file @
6a33647
...
...
@@ -157,7 +157,17 @@ func (e *Email) Bytes() ([]byte, error) {
}
// Add attach file to the send mail
func
(
e
*
Email
)
AttachFile
(
filename
string
,
id
string
)
(
a
*
Attachment
,
err
error
)
{
func
(
e
*
Email
)
AttachFile
(
args
...
string
)
(
a
*
Attachment
,
err
error
)
{
argsLength
:=
len
(
args
)
if
argsLength
<
1
||
argsLength
>
2
{
return
}
filename
:=
args
[
0
]
id
:=
""
if
argsLength
>
1
{
id
=
args
[
1
]
}
id
=
args
[
1
]
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
...
...
@@ -169,7 +179,18 @@ func (e *Email) AttachFile(filename string, id string) (a *Attachment, err error
// Attach is used to attach content from an io.Reader to the email.
// Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type.
func
(
e
*
Email
)
Attach
(
r
io
.
Reader
,
filename
string
,
c
string
,
id
string
)
(
a
*
Attachment
,
err
error
)
{
func
(
e
*
Email
)
Attach
(
r
io
.
Reader
,
filename
string
,
ci
...
string
)
(
a
*
Attachment
,
err
error
)
{
args
:=
ci
argsLength
:=
len
(
args
)
if
argsLength
<
1
||
argsLength
>
2
{
return
}
c
:=
args
[
0
]
id
:=
""
if
argsLength
>
1
{
id
=
args
[
1
]
}
id
=
args
[
1
]
var
buffer
bytes
.
Buffer
if
_
,
err
=
io
.
Copy
(
&
buffer
,
r
);
err
!=
nil
{
return
...
...
@@ -189,7 +210,7 @@ func (e *Email) Attach(r io.Reader, filename string, c string, id string) (a *At
if
id
!=
""
{
at
.
Header
.
Set
(
"Content-Disposition"
,
fmt
.
Sprintf
(
"inline;
\r\n
filename=
\"
%s
\"
"
,
filename
))
at
.
Header
.
Set
(
"Content-ID"
,
fmt
.
Sprintf
(
"<%s>"
,
id
))
}
else
{
}
else
{
at
.
Header
.
Set
(
"Content-Disposition"
,
fmt
.
Sprintf
(
"attachment;
\r\n
filename=
\"
%s
\"
"
,
filename
))
}
at
.
Header
.
Set
(
"Content-Transfer-Encoding"
,
"base64"
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment