gomail

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 16 Imported by: 1

README

Introduction

gomail We have downloaded and modified this gomail package originally from the author alexcesaro of #gomail in which the package seems no longer maintaining, that's why we take this very good package to maintain it for other gopher developers.

Gomail is a simple and efficient package to send emails. It is well tested and documented.

Gomail can only send emails using an SMTP server. But the API is flexible and it is easy to implement other methods for sending emails using a local Postfix, an API, etc.

It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used.

Features

Gomail supports:

  • Attachments
  • Embedded images
  • HTML and text templates
  • Automatic encoding of special characters
  • SSL and TLS
  • Sending multiple emails with the same SMTP connection

Installation

go get -u github.com/itrepablik/gomail

FAQ

x509: certificate signed by unknown authority

If you get this error it means the certificate used by the SMTP server is not considered valid by the client running Gomail. As a quick workaround you can bypass the verification of the server's certificate chain and host name by using SetTLSConfig:

package main

import (
	"crypto/tls"

	"github.com/itrepablik/gomail"
)

func main() {
	d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
	d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

    // Send emails using d.
}

Note, however, that this is insecure and should not be used in production.

We also have another package in which gomail and sendgrid are supported, kindly install sulat package.

go get -u github.com/itrepablik/sulat

Usage of Sulat Package

This is an example usage of how to send an email using gomail package with #sulat package:

package main

import (
	"fmt"

	"github.com/itrepablik/itrlog"
	"github.com/itrepablik/sulat"
)

// HTMLHeader is the HTML skeletal framework head section of the standard HTML structure that serves as an email content
const HTMLHeader = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Email Notifications</title>
</head>
<body style="margin:0px; background: #f8f8f8; ">
    <div width="100%" style="background: #f8f8f8; padding: 0px 0px; font-family:arial; line-height:28px; height:100%;  width: 100%; color: #514d6a;">
        <div style="max-width: 700px; padding:50px 0;  margin: 0px auto; font-size: 14px">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; margin-bottom: 20px">
                <tbody>
                    <tr>
                        <td style="vertical-align: top; padding-bottom:30px;" align="center">
                            <a href="https://itrepablik.com" target="_blank">
                                <img src="https://itrepablik.com/static/assets/images/ITRepablik_top_logo.png" style="width:230px; height:auto;" alt="xtreme admin" style="border:none">
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>`

// HTMLFooter is the HTML skeletal framework footer section of the standard HTML structure that serves as an email content
const HTMLFooter = `</div></div></body></html>`

// bodyHTML is your custom email contents, this is just an example of a password reset auto email from your Go's project
var bodyHTML = `<div style="padding: 40px; background: #fff;">
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
	<tbody>
		<tr>
			<td style="">
				<h1 style="font-size:14px; font-family:arial; margin:0px; font-weight:bold;">Hi politz,</h1>
			</td>
		</tr>
		<tr>
			<td style="padding:10px 0 30px 0;">
				<p>A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request, please reset your password:</p>
				<center>
				<a href="#" style="display: inline-block; padding: 11px 30px; margin: 20px 0px 30px; font-size: 15px; color: #fff; background: #4fc3f7; border-radius: 60px; text-decoration:none;">Reset Password</a>
				</center>
				<b>- Thanks (ITRepablik.com Team)</b>
			</td>
		</tr>
		<tr>
			<td style="padding-top:20px;">
				If the button above does not work, try copying and pasting the URL into your browser.<br/>
				<a href="#">https://itrepablik.com/activate/abcde12345</a><br/>
				If you continue to have problems, please feel free to contact us at <a href="mailto:support@itrepablik.com">support@itrepablik.com</a>
			</td>
		</tr>
	</tbody>
</table>
</div>`

// FullHTML use this when you preferred the full HTML template as your content
var FullHTML = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Email Notifications</title>
</head>
<body style="margin:0px; background: #f8f8f8; ">
    <div width="100%" style="background: #f8f8f8; padding: 0px 0px; font-family:arial; line-height:28px; height:100%;  width: 100%; color: #514d6a;">
        <div style="max-width: 700px; padding:50px 0;  margin: 0px auto; font-size: 14px">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; margin-bottom: 20px">
                <tbody>
                    <tr>
                        <td style="vertical-align: top; padding-bottom:30px;" align="center">
                            <a href="https://itrepablik.com" target="_blank">
                                <img src="https://itrepablik.com/static/assets/images/ITRepablik_top_logo.png" style="width:230px; height:auto;" alt="xtreme admin" style="border:none">
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div style="padding: 40px; background: #fff;">
                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
                    <tbody>
                        <tr>
                            <td style="">
                                <h1 style="font-size:14px; font-family:arial; margin:0px; font-weight:bold;">Hi UserName,</h1>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding:10px 0 30px 0;">
                                <p>A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request, please reset your password:</p>
                                <center>
                                <a href="#" style="display: inline-block; padding: 11px 30px; margin: 20px 0px 30px; font-size: 15px; color: #fff; background: #4fc3f7; border-radius: 60px; text-decoration:none;">Reset Password</a>
                                </center>
                                <b>- Thanks (ITRepablik.com Team)</b>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-top:20px;">
                                If the button above does not work, try copying and pasting the URL into your browser.<br/>
                                <a href="#">https://itrepablik.com/activate/hello-world</a><br/>
                                If you continue to have problems, please feel free to contact us at <a href="mailto:support@itrepablik.com">support@itrepablik.com</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div style="text-align: center; font-size: 12px; color: #b2b2b5; margin-top: 20px">
                <p> Powered by ITRepablik.com
                    <br>
                    <a href="javascript: void(0);" style="color: #b2b2b5; text-decoration: underline;">Unsubscribe</a>
                </p>
            </div>
        </div>
    </div>
</body>
</html>`

// SMTPCon initialize this variable globally sulat.SMTPConfig{} for the 'SMTP' Classic
var SMTPCon = sulat.SMTPConfig{}

func init() {
	// Initialize the 'SMTP' classic
	SMTPCon = sulat.SMTPConfig{
		Host:     "smtp.host.com",
		Port:     25,
		UserName: "your@email.com",
		Password: "your_smtp_password",
	}
}

func main() {
	// This is how to use the 'sulat' package using 'SendGrid' API key
	// Prepare the HTML email content
	mailOpt := &sulat.MailClassicHeader{
		Subject: "Inquiry for the new ITR Sulat package",
		From:    "support@itrepablik.com",
		To:      []string{"email1@mail.com", "email2@mail.com"},
		CC:      []string{"email3@mail.com", "email4@mail.com"},
		BCC:     []string{"email5@mail.com", "email6@mail.com"},
	}

	//*****************************************************************************
	// Use only either 'Method 1' or 'Method 2' for your email HTML content
	//*****************************************************************************

	// Method 1: Set full HTML template as your email content.
	// e.g email marketing campaign template
	htmlContent, err := sulat.SetHTML(&sulat.EmailHTMLFormat{
		IsFullHTML:       true,
		FullHTMLTemplate: FullHTML,
	})

	// Method 2: Set this standard HTML header and footer but with different HTML body
	// this is usually use when you've fixed header and footer content
	// e.g standard email notifications such as password reset, email confirmation, etc.
	htmlContent, err = sulat.SetHTML(&sulat.EmailHTMLFormat{
		IsFullHTML: false,
		HTMLHeader: HTMLHeader,
		HTMLBody:   bodyHTML,
		HTMLFooter: HTMLFooter,
	})

	// Send email using 'SMTP' classic method
	isSend, err := sulat.SendEmailSMTP(mailOpt, htmlContent, &SMTPCon)
	if err != nil {
		itrlog.Fatal(err)
	}
	fmt.Println("isSend: ", isSend)
}

Subscribe to Maharlikans Code Youtube Channel:

Please consider subscribing to my Youtube Channel to recognize my work on this package. Thank you for your support! https://www.youtube.com/channel/UCdAVUmldU9Jn2VntuQChHqQ/

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Overview

Package gomail provides a simple interface to compose emails and to mail them efficiently.

More info on Github: https://github.com/go-gomail/gomail

Example
package main

import (
	"github.com/itrepablik/gomail"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "alex@example.com")
	m.SetHeader("To", "bob@example.com", "cora@example.com")
	m.SetAddressHeader("Cc", "dan@example.com", "Dan")
	m.SetHeader("Subject", "Hello!")
	m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
	m.Attach("/home/Alex/lolcat.jpg")

	d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")

	// Send the email to Bob, Cora and Dan.
	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}
Output:

Example (Daemon)

A daemon that listens to a channel and sends all incoming messages.

package main

import (
	"log"
	"time"

	"github.com/itrepablik/gomail"
)

func main() {
	ch := make(chan *gomail.Message)

	go func() {
		d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")

		var s gomail.SendCloser
		var err error
		open := false
		for {
			select {
			case m, ok := <-ch:
				if !ok {
					return
				}
				if !open {
					if s, err = d.Dial(); err != nil {
						panic(err)
					}
					open = true
				}
				if err := gomail.Send(s, m); err != nil {
					log.Print(err)
				}
			// Close the connection to the SMTP server if no email was sent in
			// the last 30 seconds.
			case <-time.After(30 * time.Second):
				if open {
					if err := s.Close(); err != nil {
						panic(err)
					}
					open = false
				}
			}
		}
	}()

	// Use the channel in your program to send emails.

	// Close the channel to stop the mail daemon.
	close(ch)
}
Output:

Example (Newsletter)

Efficiently send a customized newsletter to a list of recipients.

package main

import (
	"fmt"
	"log"

	"github.com/itrepablik/gomail"
)

func main() {
	// The list of recipients.
	var list []struct {
		Name    string
		Address string
	}

	d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
	s, err := d.Dial()
	if err != nil {
		panic(err)
	}

	m := gomail.NewMessage()
	for _, r := range list {
		m.SetHeader("From", "no-reply@example.com")
		m.SetAddressHeader("To", r.Address, r.Name)
		m.SetHeader("Subject", "Newsletter #1")
		m.SetBody("text/html", fmt.Sprintf("Hello %s!", r.Name))

		if err := gomail.Send(s, m); err != nil {
			log.Printf("Could not send email to %q: %v", r.Address, err)
		}
		m.Reset()
	}
}
Output:

Example (NoAuth)

Send an email using a local SMTP server.

package main

import (
	"github.com/itrepablik/gomail"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "from@example.com")
	m.SetHeader("To", "to@example.com")
	m.SetHeader("Subject", "Hello!")
	m.SetBody("text/plain", "Hello!")

	d := gomail.Dialer{Host: "localhost", Port: 587}
	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}
Output:

Example (NoSMTP)

Send an email using an API or postfix.

package main

import (
	"fmt"
	"io"

	"github.com/itrepablik/gomail"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "from@example.com")
	m.SetHeader("To", "to@example.com")
	m.SetHeader("Subject", "Hello!")
	m.SetBody("text/plain", "Hello!")

	s := gomail.SendFunc(func(from string, to []string, msg io.WriterTo) error {
		// Implements you email-sending function, for example by calling
		// an API, or running postfix, etc.
		fmt.Println("From:", from)
		fmt.Println("To:", to)
		return nil
	})

	if err := gomail.Send(s, m); err != nil {
		panic(err)
	}
}
Output:

From: from@example.com
To: [to@example.com]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(s Sender, msg ...*Message) error

Send sends emails using the given Sender.

Types

type Dialer

type Dialer struct {
	// Host represents the host of the SMTP server.
	Host string
	// Port represents the port of the SMTP server.
	Port int
	// Username is the username to use to authenticate to the SMTP server.
	Username string
	// Password is the password to use to authenticate to the SMTP server.
	Password string
	// Auth represents the authentication mechanism used to authenticate to the
	// SMTP server.
	Auth smtp.Auth
	// SSL defines whether an SSL connection is used. It should be false in
	// most cases since the authentication mechanism should use the STARTTLS
	// extension instead.
	SSL bool
	// TSLConfig represents the TLS configuration used for the TLS (when the
	// STARTTLS extension is used) or SSL connection.
	TLSConfig *tls.Config
	// LocalName is the hostname sent to the SMTP server with the HELO command.
	// By default, "localhost" is sent.
	LocalName string
}

A Dialer is a dialer to an SMTP server.

func NewDialer

func NewDialer(host string, port int, username, password string) *Dialer

NewDialer returns a new SMTP Dialer. The given parameters are used to connect to the SMTP server.

func NewPlainDialer deprecated

func NewPlainDialer(host string, port int, username, password string) *Dialer

NewPlainDialer returns a new SMTP Dialer. The given parameters are used to connect to the SMTP server.

Deprecated: Use NewDialer instead.

func (*Dialer) Dial

func (d *Dialer) Dial() (SendCloser, error)

Dial dials and authenticates to an SMTP server. The returned SendCloser should be closed when done using it.

func (*Dialer) DialAndSend

func (d *Dialer) DialAndSend(m ...*Message) error

DialAndSend opens a connection to the SMTP server, sends the given emails and closes the connection.

type Encoding

type Encoding string

Encoding represents a MIME encoding scheme like quoted-printable or base64.

const (
	// QuotedPrintable represents the quoted-printable encoding as defined in
	// RFC 2045.
	QuotedPrintable Encoding = "quoted-printable"
	// Base64 represents the base64 encoding as defined in RFC 2045.
	Base64 Encoding = "base64"
	// Unencoded can be used to avoid encoding the body of an email. The headers
	// will still be encoded using quoted-printable encoding.
	Unencoded Encoding = "8bit"
)

type FileSetting

type FileSetting func(*file)

A FileSetting can be used as an argument in Message.Attach or Message.Embed.

func Rename

func Rename(name string) FileSetting

Rename is a file setting to set the name of the attachment if the name is different than the filename on disk.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.Attach("/tmp/0000146.jpg", gomail.Rename("picture.jpg"))
}
Output:

func SetCopyFunc

func SetCopyFunc(f func(io.Writer) error) FileSetting

SetCopyFunc is a file setting to replace the function that runs when the message is sent. It should copy the content of the file to the io.Writer.

The default copy function opens the file with the given filename, and copy its content to the io.Writer.

Example
package main

import (
	"io"

	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.Attach("foo.txt", gomail.SetCopyFunc(func(w io.Writer) error {
		_, err := w.Write([]byte("Content of foo.txt"))
		return err
	}))
}
Output:

func SetHeader

func SetHeader(h map[string][]string) FileSetting

SetHeader is a file setting to set the MIME header of the message part that contains the file content.

Mandatory headers are automatically added if they are not set when sending the email.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	h := map[string][]string{"Content-ID": {"<foo@bar.mail>"}}
	m.Attach("foo.jpg", gomail.SetHeader(h))
}
Output:

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents an email.

func NewMessage

func NewMessage(settings ...MessageSetting) *Message

NewMessage creates a new message. It uses UTF-8 and quoted-printable encoding by default.

func (*Message) AddAlternative

func (m *Message) AddAlternative(contentType, body string, settings ...PartSetting)

AddAlternative adds an alternative part to the message.

It is commonly used to send HTML emails that default to the plain text version for backward compatibility. AddAlternative appends the new part to the end of the message. So the plain text part should be added before the HTML part. See http://en.wikipedia.org/wiki/MIME#Alternative

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetBody("text/plain", "Hello!")
	m.AddAlternative("text/html", "<p>Hello!</p>")
}
Output:

func (*Message) AddAlternativeWriter

func (m *Message) AddAlternativeWriter(contentType string, f func(io.Writer) error, settings ...PartSetting)

AddAlternativeWriter adds an alternative part to the message. It can be useful with the text/template or html/template packages.

Example
package main

import (
	"html/template"
	"io"

	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	t := template.Must(template.New("example").Parse("Hello {{.}}!"))
	m.AddAlternativeWriter("text/plain", func(w io.Writer) error {
		return t.Execute(w, "Bob")
	})
}
Output:

func (*Message) Attach

func (m *Message) Attach(filename string, settings ...FileSetting)

Attach attaches the files to the email.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.Attach("/tmp/image.jpg")
}
Output:

func (*Message) Embed

func (m *Message) Embed(filename string, settings ...FileSetting)

Embed embeds the images to the email.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.Embed("/tmp/image.jpg")
	m.SetBody("text/html", `<img src="cid:image.jpg" alt="My image" />`)
}
Output:

func (*Message) FormatAddress

func (m *Message) FormatAddress(address, name string) string

FormatAddress formats an address and a name as a valid RFC 5322 address.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetHeader("To", m.FormatAddress("bob@example.com", "Bob"), m.FormatAddress("cora@example.com", "Cora"))
}
Output:

func (*Message) FormatDate

func (m *Message) FormatDate(date time.Time) string

FormatDate formats a date as a valid RFC 5322 date.

Example
package main

import (
	"time"

	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetHeaders(map[string][]string{
		"X-Date": {m.FormatDate(time.Now())},
	})
}
Output:

func (*Message) GetHeader

func (m *Message) GetHeader(field string) []string

GetHeader gets a header field.

func (*Message) Reset

func (m *Message) Reset()

Reset resets the message so it can be reused. The message keeps its previous settings so it is in the same state that after a call to NewMessage.

func (*Message) SetAddressHeader

func (m *Message) SetAddressHeader(field, address, name string)

SetAddressHeader sets an address to the given header field.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetAddressHeader("To", "bob@example.com", "Bob")
}
Output:

func (*Message) SetBody

func (m *Message) SetBody(contentType, body string, settings ...PartSetting)

SetBody sets the body of the message. It replaces any content previously set by SetBody, AddAlternative or AddAlternativeWriter.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetBody("text/plain", "Hello!")
}
Output:

func (*Message) SetDateHeader

func (m *Message) SetDateHeader(field string, date time.Time)

SetDateHeader sets a date to the given header field.

Example
package main

import (
	"time"

	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetDateHeader("X-Date", time.Now())
}
Output:

func (*Message) SetHeader

func (m *Message) SetHeader(field string, value ...string)

SetHeader sets a value to the given header field.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetHeader("Subject", "Hello!")
}
Output:

func (*Message) SetHeaders

func (m *Message) SetHeaders(h map[string][]string)

SetHeaders sets the message headers.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetHeaders(map[string][]string{
		"From":    {m.FormatAddress("alex@example.com", "Alex")},
		"To":      {"bob@example.com", "cora@example.com"},
		"Subject": {"Hello"},
	})
}
Output:

func (*Message) WriteTo

func (m *Message) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo. It dumps the whole message into w.

type MessageSetting

type MessageSetting func(m *Message)

A MessageSetting can be used as an argument in NewMessage to configure an email.

func SetCharset

func SetCharset(charset string) MessageSetting

SetCharset is a message setting to set the charset of the email.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m = gomail.NewMessage(gomail.SetCharset("ISO-8859-1"))
}
Output:

func SetEncoding

func SetEncoding(enc Encoding) MessageSetting

SetEncoding is a message setting to set the encoding of the email.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m = gomail.NewMessage(gomail.SetEncoding(gomail.Base64))
}
Output:

type PartSetting

type PartSetting func(*part)

A PartSetting can be used as an argument in Message.SetBody, Message.AddAlternative or Message.AddAlternativeWriter to configure the part added to a message.

func SetPartEncoding

func SetPartEncoding(e Encoding) PartSetting

SetPartEncoding sets the encoding of the part added to the message. By default, parts use the same encoding than the message.

Example
package main

import (
	"github.com/itrepablik/gomail"
)

var m *gomail.Message

func main() {
	m.SetBody("text/plain", "Hello!", gomail.SetPartEncoding(gomail.Unencoded))
}
Output:

type SendCloser

type SendCloser interface {
	Sender
	Close() error
}

SendCloser is the interface that groups the Send and Close methods.

type SendFunc

type SendFunc func(from string, to []string, msg io.WriterTo) error

A SendFunc is a function that sends emails to the given addresses.

The SendFunc type is an adapter to allow the use of ordinary functions as email senders. If f is a function with the appropriate signature, SendFunc(f) is a Sender object that calls f.

func (SendFunc) Send

func (f SendFunc) Send(from string, to []string, msg io.WriterTo) error

Send calls f(from, to, msg).

type Sender

type Sender interface {
	Send(from string, to []string, msg io.WriterTo) error
}

Sender is the interface that wraps the Send method.

Send sends an email to the given addresses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL