go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/impl/prod/mail.go (about)

     1  // Copyright 2015 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package prod
    16  
    17  import (
    18  	"context"
    19  
    20  	"google.golang.org/appengine/mail"
    21  
    22  	gae_mail "go.chromium.org/luci/gae/service/mail"
    23  )
    24  
    25  // useMail adds a mail service implementation to context, accessible
    26  // by "go.chromium.org/luci/gae/service/mail".Raw(c) or the exported mail service
    27  // methods.
    28  func useMail(c context.Context) context.Context {
    29  	return gae_mail.SetFactory(c, func(ci context.Context) gae_mail.RawInterface {
    30  		return mailImpl{getAEContext(ci)}
    31  	})
    32  }
    33  
    34  type mailImpl struct {
    35  	aeCtx context.Context
    36  }
    37  
    38  func (m mailImpl) Send(msg *gae_mail.Message) error {
    39  	return mail.Send(m.aeCtx, msg.ToSDKMessage())
    40  }
    41  
    42  func (m mailImpl) SendToAdmins(msg *gae_mail.Message) error {
    43  	return mail.Send(m.aeCtx, msg.ToSDKMessage())
    44  }
    45  
    46  func (m mailImpl) GetTestable() gae_mail.Testable { return nil }