@@ -47,6 +47,23 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er
4747 }
4848 }
4949
50+ if config .Smtp .Enabled {
51+ log .Printf ("%s validating smtp connection" , validate .EmojiFingerPointRight )
52+
53+ smtpQuery := `mutation sendTestEmail($to: String!) {
54+ sendTestEmail(to: $to)
55+ }`
56+ smtpVars := map [string ]interface {}{
57+ "to" : config .Smtp .To ,
58+ }
59+
60+ result , err := checkSmtp (ctx , client , smtpQuery , smtpVars )
61+ if err != nil {
62+ return err
63+ }
64+ log .Printf ("%s '%s'" , validate .SuccessEmoji , result )
65+ }
66+
5067 if config .Insight .Title != "" {
5168 log .Printf ("%s validating code insight" , validate .EmojiFingerPointRight )
5269
@@ -130,6 +147,27 @@ func searchMatchCount(ctx context.Context, client api.Client, searchExpr string)
130147 return result .Search .Results .MatchCount , nil
131148}
132149
150+ func checkSmtp (ctx context.Context , client api.Client , query string , variables map [string ]interface {}) (string , error ) {
151+ q := clientQuery {
152+ opName : "CheckSmtpConfig" ,
153+ query : query ,
154+ variables : variables ,
155+ }
156+
157+ var result struct {
158+ SendTestEmail string `json:"sendTestEmail"`
159+ }
160+
161+ ok , err := client .NewRequest (q .query , q .variables ).Do (ctx , & result )
162+ if err != nil {
163+ return "" , errors .Wrap (err , "sendTestEmail failed" )
164+ }
165+ if ! ok {
166+ return "" , errors .New ("sendTestEmail failed, no data to unmarshal" )
167+ }
168+ return result .SendTestEmail , nil
169+ }
170+
133171func repoCloneTimeout (ctx context.Context , client api.Client , repo string , srv ExternalService ) (bool , error ) {
134172 for i := 0 ; i < srv .MaxRetries ; i ++ {
135173 repos , err := listClonedRepos (ctx , client , []string {repo })
0 commit comments