Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature -- Added attach via pipe. #112

Open
rmasci opened this issue Mar 27, 2018 · 1 comment
Open

New feature -- Added attach via pipe. #112

rmasci opened this issue Mar 27, 2018 · 1 comment

Comments

@rmasci
Copy link

rmasci commented Mar 27, 2018

Added the following code to message.go. This adds the ability for the user to send email from the command line of a server using a pipe. This is very useful when sending yourself and / or others a chunk from a log file.

tail -100 SomeLogfile.log | goemailprog -t [email protected] -s "logfile" -m "last 100 from SomeLogfile" -p "SomeLogfile.log"

---- code to add to messages.go ---

func (m *Message) pipeFile(list []*file, name string) []*file {
f := &file{
Name: name,
Header: make(map[string][]string),
CopyFunc: func(w io.Writer) error {
h := bufio.NewReader(os.Stdin)
if _, err := io.Copy(w, h); err != nil {
return err
}
return nil
},
}

if list == nil {
	return []*file{f}
}

return append(list, f)

}

// Pipe attaches the files to the email, user pipes it in from stdin.
func (m *Message) Pipe(filename string, settings ...FileSetting) {
m.attachments = m.pipeFile(m.attachments, filename)
}

@pedromorgan
Copy link

See #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants