├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── SmtpTelegramGateway.sln └── SmtpTelegramGateway ├── .editorconfig ├── Configuration.cs ├── ILoggerExtensions.cs ├── Program.cs ├── Program.ico ├── Smtp.cs ├── SmtpTelegramGateway.csproj ├── Telegram.cs └── appsettings.yaml /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb 341 | /SmtpTelegramRelay/Properties/launchSettings.json 342 | /SmtpTelegramRelay/appsettings.Development.yaml 343 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 7orlum 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is SmtpTelegramGateway 2 | 3 | SmtpTelegramGateway is an SMTP gateway that forwards received emails to specified Telegram chats via your Telegram bot. Runs as a windows service, as a unix daemon or as a standalone application. Fully written in C#. 4 | 5 | # Setup 6 | 7 | 1. Edit `appsettings.yaml`. At least specify a telegram bot token and a chat id. 8 | ```yaml 9 | # The port that the gateway will listen on to receive SMTP e-mail messages, the default is 25. 10 | # No authorization is required when connecting to this port, select Basic Authorizathion if it is required 11 | SmtpPort: 25 12 | # Your token for the Telegram bot, get it at https://t.me/BotFather when registering the bot 13 | TelegramBotToken: SPECIFY THERE TELEGRAM BOT TOKEN 14 | # Define here a list of email addresses and telegram chats that will receive emails sent to these addresses. 15 | # Use an asterisk "*" instead of an email address to send all emails to some telegram chat 16 | # If you specify a Telegram user chat, the user must be subscribed to the bot 17 | # If you specify a Telegram group chat, you may need to add a minus sign prior to the group id, the bot must be added to the group 18 | # If you specify a Telegram channel chat, you may need to add -100 prior to the channel id, the bot must be added to the channel admins and given the right "Post in the channel" 19 | # For public channel chat, you can specify the channel public @username instead of the channel id 20 | Routing: 21 | - Email: "*" 22 | TelegramChat: SPECIFY THERE TELEGRAM USERID, GROUPID, CHANNELID OR @USERNAME 23 | - Email: example@test.com 24 | TelegramChat: SPECIFY THERE TELEGRAM USERID, GROUPID, CHANNELID OR @USERNAME 25 | # Logging Level. Set to Debug to see the details of the communication between your mail program and the gateway. 26 | # Set to Error to see less information 27 | Logging: 28 | LogLevel: 29 | Default: Debug 30 | ``` 31 | 2. Register and run 32 | - Run `SmtpTelegramGateway.exe` as a standalone application 33 | - Or register the program as a windows service 34 | ```ps 35 | sc.exe create "SMTP Telegram Gateway" binpath="C:\Program Files\SmtpTelegramGateway\SmtpTelegramGateway.exe" start=auto obj="NT AUTHORITY\LocalService" 36 | ``` 37 | then start the windows service 38 | ```ps 39 | sc.exe start "SMTP Telegram Gateway" 40 | ``` 41 | - Or register the program as a systemd service in unix-like operating systems. Create a configuration file `/etc/systemd/system/smtp-telegram-gateway.service` looking as follows: 42 | ```ini 43 | [Unit] 44 | Description=SMTP Telegram Gateway 45 | [Service] 46 | Type=simple 47 | ExecStart=/usr/sbin/SmtpTelegramGateway 48 | [Install] 49 | WantedBy=multi-user.target 50 | ``` 51 | then say systemd to load the new configuration file 52 | ```console 53 | sudo systemctl daemon-reload 54 | ``` 55 | and run the service 56 | ```console 57 | sudo systemctl start smtp-telegram-gateway.service` 58 | ``` 59 | 60 | 4. Send a test email and get it in telegram. Use `localhost` as an SMTP server address, `25` as a port and no authentifiacation or, if necessary, select the basic authentication method with a fake username and password. 61 | -------------------------------------------------------------------------------- /SmtpTelegramGateway.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34511.84 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C4594BE9-D036-4B88-9A43-47636EF59BEB}" 7 | ProjectSection(SolutionItems) = preProject 8 | LICENSE = LICENSE 9 | README.md = README.md 10 | EndProjectSection 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmtpTelegramGateway", "SmtpTelegramGateway\SmtpTelegramGateway.csproj", "{C733124D-B4BE-4163-B641-AC508D3A7C14}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {C733124D-B4BE-4163-B641-AC508D3A7C14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {C733124D-B4BE-4163-B641-AC508D3A7C14}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {C733124D-B4BE-4163-B641-AC508D3A7C14}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {C733124D-B4BE-4163-B641-AC508D3A7C14}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {558718DC-E10B-4296-AB14-9DA53CEDF24C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/.editorconfig: -------------------------------------------------------------------------------- 1 | # Remove the line below if you want to inherit .editorconfig settings from higher directories 2 | root = true 3 | 4 | # C# files 5 | [*.cs] 6 | 7 | #### Core EditorConfig Options #### 8 | 9 | # Indentation and spacing 10 | indent_size = 4 11 | indent_style = space 12 | tab_width = 4 13 | 14 | # New line preferences 15 | end_of_line = crlf 16 | insert_final_newline = false 17 | 18 | #### .NET Code Actions #### 19 | 20 | # Type members 21 | dotnet_hide_advanced_members = false 22 | dotnet_member_insertion_location = with_other_members_of_the_same_kind 23 | dotnet_property_generation_behavior = prefer_throwing_properties 24 | 25 | # Symbol search 26 | dotnet_search_reference_assemblies = true 27 | 28 | #### .NET Coding Conventions #### 29 | 30 | # Organize usings 31 | dotnet_separate_import_directive_groups = false 32 | dotnet_sort_system_directives_first = false 33 | file_header_template = unset 34 | 35 | # this. and Me. preferences 36 | dotnet_style_qualification_for_event = false 37 | dotnet_style_qualification_for_field = false 38 | dotnet_style_qualification_for_method = false 39 | dotnet_style_qualification_for_property = false 40 | 41 | # Language keywords vs BCL types preferences 42 | dotnet_style_predefined_type_for_locals_parameters_members = true 43 | dotnet_style_predefined_type_for_member_access = true 44 | 45 | # Parentheses preferences 46 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity 47 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity 48 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary 49 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity 50 | 51 | # Modifier preferences 52 | dotnet_style_require_accessibility_modifiers = for_non_interface_members 53 | 54 | # Expression-level preferences 55 | dotnet_prefer_system_hash_code = true 56 | dotnet_style_coalesce_expression = true 57 | dotnet_style_collection_initializer = true 58 | dotnet_style_explicit_tuple_names = true 59 | dotnet_style_namespace_match_folder = true 60 | dotnet_style_null_propagation = true 61 | dotnet_style_object_initializer = true 62 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 63 | dotnet_style_prefer_auto_properties = true 64 | dotnet_style_prefer_collection_expression = when_types_loosely_match 65 | dotnet_style_prefer_compound_assignment = true 66 | dotnet_style_prefer_conditional_expression_over_assignment = true 67 | dotnet_style_prefer_conditional_expression_over_return = true 68 | dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed 69 | dotnet_style_prefer_inferred_anonymous_type_member_names = true 70 | dotnet_style_prefer_inferred_tuple_names = true 71 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true 72 | dotnet_style_prefer_simplified_boolean_expressions = true 73 | dotnet_style_prefer_simplified_interpolation = true 74 | 75 | # Field preferences 76 | dotnet_style_readonly_field = true 77 | 78 | # Parameter preferences 79 | dotnet_code_quality_unused_parameters = all 80 | 81 | # Suppression preferences 82 | dotnet_remove_unnecessary_suppression_exclusions = none 83 | 84 | # New line preferences 85 | dotnet_style_allow_multiple_blank_lines_experimental = true 86 | dotnet_style_allow_statement_immediately_after_block_experimental = true 87 | 88 | #### C# Coding Conventions #### 89 | 90 | # var preferences 91 | csharp_style_var_elsewhere = true:silent 92 | csharp_style_var_for_built_in_types = true:silent 93 | csharp_style_var_when_type_is_apparent = true:silent 94 | 95 | # Expression-bodied members 96 | csharp_style_expression_bodied_accessors = true:silent 97 | csharp_style_expression_bodied_constructors = false:silent 98 | csharp_style_expression_bodied_indexers = true:silent 99 | csharp_style_expression_bodied_lambdas = true:silent 100 | csharp_style_expression_bodied_local_functions = false:silent 101 | csharp_style_expression_bodied_methods = false:silent 102 | csharp_style_expression_bodied_operators = false:silent 103 | csharp_style_expression_bodied_properties = true:silent 104 | 105 | # Pattern matching preferences 106 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 107 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 108 | csharp_style_prefer_extended_property_pattern = true:suggestion 109 | csharp_style_prefer_not_pattern = true:suggestion 110 | csharp_style_prefer_pattern_matching = true:silent 111 | csharp_style_prefer_switch_expression = true:suggestion 112 | 113 | # Null-checking preferences 114 | csharp_style_conditional_delegate_call = true:suggestion 115 | 116 | # Modifier preferences 117 | csharp_prefer_static_anonymous_function = true:suggestion 118 | csharp_prefer_static_local_function = true:suggestion 119 | csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async 120 | csharp_style_prefer_readonly_struct = true:suggestion 121 | csharp_style_prefer_readonly_struct_member = true:suggestion 122 | 123 | # Code-block preferences 124 | csharp_prefer_braces = true:silent 125 | csharp_prefer_simple_using_statement = true:suggestion 126 | csharp_prefer_system_threading_lock = true:suggestion 127 | csharp_style_namespace_declarations = file_scoped:silent 128 | csharp_style_prefer_method_group_conversion = true:silent 129 | csharp_style_prefer_primary_constructors = true:suggestion 130 | csharp_style_prefer_top_level_statements = false:silent 131 | 132 | # Expression-level preferences 133 | csharp_prefer_simple_default_expression = true:suggestion 134 | csharp_style_deconstructed_variable_declaration = true:suggestion 135 | csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion 136 | csharp_style_inlined_variable_declaration = true:suggestion 137 | csharp_style_prefer_index_operator = true:suggestion 138 | csharp_style_prefer_local_over_anonymous_function = true:suggestion 139 | csharp_style_prefer_null_check_over_type_check = true:suggestion 140 | csharp_style_prefer_range_operator = true:suggestion 141 | csharp_style_prefer_tuple_swap = true:suggestion 142 | csharp_style_prefer_utf8_string_literals = true:suggestion 143 | csharp_style_throw_expression = true:suggestion 144 | csharp_style_unused_value_assignment_preference = discard_variable:suggestion 145 | csharp_style_unused_value_expression_statement_preference = discard_variable:silent 146 | 147 | # 'using' directive preferences 148 | csharp_using_directive_placement = outside_namespace:silent 149 | 150 | # New line preferences 151 | csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent 152 | csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent 153 | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent 154 | csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent 155 | csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent 156 | 157 | #### C# Formatting Rules #### 158 | 159 | # New line preferences 160 | csharp_new_line_before_catch = true 161 | csharp_new_line_before_else = true 162 | csharp_new_line_before_finally = true 163 | csharp_new_line_before_members_in_anonymous_types = true 164 | csharp_new_line_before_members_in_object_initializers = true 165 | csharp_new_line_before_open_brace = all 166 | csharp_new_line_between_query_expression_clauses = true 167 | 168 | # Indentation preferences 169 | csharp_indent_block_contents = true 170 | csharp_indent_braces = false 171 | csharp_indent_case_contents = true 172 | csharp_indent_case_contents_when_block = true 173 | csharp_indent_labels = no_change 174 | csharp_indent_switch_labels = true 175 | 176 | # Space preferences 177 | csharp_space_after_cast = false 178 | csharp_space_after_colon_in_inheritance_clause = true 179 | csharp_space_after_comma = true 180 | csharp_space_after_dot = false 181 | csharp_space_after_keywords_in_control_flow_statements = true 182 | csharp_space_after_semicolon_in_for_statement = true 183 | csharp_space_around_binary_operators = before_and_after 184 | csharp_space_around_declaration_statements = false 185 | csharp_space_before_colon_in_inheritance_clause = true 186 | csharp_space_before_comma = false 187 | csharp_space_before_dot = false 188 | csharp_space_before_open_square_brackets = false 189 | csharp_space_before_semicolon_in_for_statement = false 190 | csharp_space_between_empty_square_brackets = false 191 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 192 | csharp_space_between_method_call_name_and_opening_parenthesis = false 193 | csharp_space_between_method_call_parameter_list_parentheses = false 194 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 195 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 196 | csharp_space_between_method_declaration_parameter_list_parentheses = false 197 | csharp_space_between_parentheses = false 198 | csharp_space_between_square_brackets = false 199 | 200 | # Wrapping preferences 201 | csharp_preserve_single_line_blocks = true 202 | csharp_preserve_single_line_statements = true 203 | 204 | #### Naming styles #### 205 | 206 | # Naming rules 207 | 208 | dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion 209 | dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface 210 | dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i 211 | 212 | dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion 213 | dotnet_naming_rule.types_should_be_pascal_case.symbols = types 214 | dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case 215 | 216 | dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion 217 | dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members 218 | dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case 219 | 220 | # Symbol specifications 221 | 222 | dotnet_naming_symbols.interface.applicable_kinds = interface 223 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 224 | dotnet_naming_symbols.interface.required_modifiers = 225 | 226 | dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum 227 | dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 228 | dotnet_naming_symbols.types.required_modifiers = 229 | 230 | dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method 231 | dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 232 | dotnet_naming_symbols.non_field_members.required_modifiers = 233 | 234 | # Naming styles 235 | 236 | dotnet_naming_style.pascal_case.required_prefix = 237 | dotnet_naming_style.pascal_case.required_suffix = 238 | dotnet_naming_style.pascal_case.word_separator = 239 | dotnet_naming_style.pascal_case.capitalization = pascal_case 240 | 241 | dotnet_naming_style.begins_with_i.required_prefix = I 242 | dotnet_naming_style.begins_with_i.required_suffix = 243 | dotnet_naming_style.begins_with_i.word_separator = 244 | dotnet_naming_style.begins_with_i.capitalization = pascal_case 245 | 246 | [*.{cs,vb}] 247 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 248 | tab_width = 4 249 | indent_size = 4 250 | end_of_line = crlf 251 | dotnet_style_coalesce_expression = true:suggestion 252 | dotnet_style_null_propagation = true:suggestion 253 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion 254 | dotnet_style_prefer_auto_properties = true:silent 255 | dotnet_style_object_initializer = true:suggestion 256 | dotnet_style_collection_initializer = true:suggestion 257 | dotnet_style_prefer_simplified_boolean_expressions = true:suggestion 258 | dotnet_style_prefer_conditional_expression_over_assignment = true:silent 259 | dotnet_style_prefer_conditional_expression_over_return = true:silent 260 | dotnet_style_explicit_tuple_names = true:suggestion 261 | dotnet_style_prefer_inferred_tuple_names = true:suggestion 262 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 263 | dotnet_style_prefer_compound_assignment = true:suggestion 264 | dotnet_style_prefer_simplified_interpolation = true:suggestion 265 | dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion 266 | dotnet_style_namespace_match_folder = true:suggestion 267 | dotnet_style_readonly_field = true:suggestion 268 | dotnet_style_allow_statement_immediately_after_block_experimental = true:silent 269 | dotnet_style_allow_multiple_blank_lines_experimental = true:silent 270 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent 271 | dotnet_style_predefined_type_for_member_access = true:silent 272 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent 273 | dotnet_style_qualification_for_event = false:silent 274 | dotnet_style_qualification_for_method = false:silent 275 | dotnet_style_qualification_for_property = false:silent 276 | dotnet_style_qualification_for_field = false:silent 277 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent 278 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent 279 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent 280 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent 281 | dotnet_code_quality_unused_parameters = all:suggestion -------------------------------------------------------------------------------- /SmtpTelegramGateway/Configuration.cs: -------------------------------------------------------------------------------- 1 | namespace SmtpTelegramGateway; 2 | 3 | internal sealed class Configuration 4 | { 5 | public ushort SmtpPort { get; set; } = 25; 6 | public required string TelegramBotToken { get; set; } 7 | public List Routing { get; set; } = []; 8 | 9 | internal sealed class Route 10 | { 11 | public required string Email { get; set; } 12 | public required string TelegramChat { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/ILoggerExtensions.cs: -------------------------------------------------------------------------------- 1 | using SmtpServer; 2 | using SmtpServer.Net; 3 | using SmtpServer.Tracing; 4 | 5 | namespace SmtpTelegramGateway; 6 | 7 | internal static class ILoggerExtensions 8 | { 9 | private static readonly Action _error = 10 | LoggerMessage.Define( 11 | LogLevel.Error, 12 | 0, 13 | "{Message}"); 14 | 15 | private static readonly Action _debugTelegramSendingMessage = 16 | LoggerMessage.Define( 17 | LogLevel.Debug, 18 | 0, 19 | "Telegram sending message to {Chat}"); 20 | 21 | private static readonly Action _debugSessionCreated = 22 | LoggerMessage.Define( 23 | LogLevel.Debug, 24 | 1, 25 | "SMTP session {Session} created"); 26 | 27 | private static readonly Action _debugSessionCompleted = 28 | LoggerMessage.Define( 29 | LogLevel.Debug, 30 | 2, 31 | "SMTP session {Session} completed"); 32 | 33 | private static readonly Action _debugSessionCancelled = 34 | LoggerMessage.Define( 35 | LogLevel.Debug, 36 | 3, 37 | "SMTP session {Session} cancelled"); 38 | 39 | private static readonly Action _debugSessionFaulted = 40 | LoggerMessage.Define( 41 | LogLevel.Debug, 42 | 4, 43 | "SMTP session {Session} faulted"); 44 | 45 | private static readonly Action _debugCommandExecuting = 46 | LoggerMessage.Define( 47 | LogLevel.Debug, 48 | 5, 49 | "SMTP session {Session} command {Command}"); 50 | 51 | public static void LogError(this ILogger logger, Exception e) 52 | { 53 | _error(logger, e.Message, e); 54 | } 55 | 56 | public static void LogSmtpSessionCreated(this ILogger logger, SessionEventArgs e) 57 | { 58 | var session = e.Context.Properties[EndpointListener.RemoteEndPointKey]; 59 | _debugSessionCreated(logger, session, default); 60 | } 61 | 62 | public static void LogSmtpSessionCompleted(this ILogger logger, SessionEventArgs e) 63 | { 64 | var session = e.Context.Properties[EndpointListener.RemoteEndPointKey]; 65 | _debugSessionCompleted(logger, session, default); 66 | } 67 | 68 | public static void LogSmtpSessionCancelled(this ILogger logger, SessionEventArgs e) 69 | { 70 | var session = e.Context.Properties[EndpointListener.RemoteEndPointKey]; 71 | _debugSessionCancelled(logger, session, default); 72 | } 73 | 74 | public static void LogSmtpSessionFaulted(this ILogger logger, SessionFaultedEventArgs e) 75 | { 76 | var session = e.Context.Properties[EndpointListener.RemoteEndPointKey]; 77 | _debugSessionFaulted(logger, session, default); 78 | } 79 | 80 | public static void LogSmtpCommandExecuting(this ILogger logger, SmtpCommandEventArgs e) 81 | { 82 | var session = e.Context.Properties[EndpointListener.RemoteEndPointKey]; 83 | 84 | using var writer = new StringWriter(); 85 | new TracingSmtpCommandVisitor(writer).Visit(e.Command); 86 | var command = writer.ToString(); 87 | 88 | _debugCommandExecuting(logger, session, command, default); 89 | } 90 | 91 | public static void LogTelegramSendingMessage(this ILogger logger, string chat) 92 | { 93 | _debugTelegramSendingMessage(logger, chat, default); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging.Configuration; 2 | using Microsoft.Extensions.Logging.EventLog; 3 | using SmtpServer.Storage; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace SmtpTelegramGateway; 7 | 8 | internal sealed class Program 9 | { 10 | private static void Main(string[] args) 11 | { 12 | var builder = Host.CreateApplicationBuilder(args); 13 | 14 | _ = builder.Configuration 15 | .SetBasePath(AppContext.BaseDirectory) 16 | .AddYamlFile("appsettings.yaml", optional: true, reloadOnChange: true) 17 | .AddYamlFile($"appsettings.{builder.Environment.EnvironmentName}.yaml", optional: true, reloadOnChange: true); 18 | 19 | _ = builder.Services 20 | .AddHostedService() 21 | .AddSingleton() 22 | .Configure(builder.Configuration) 23 | .AddSystemd() 24 | .AddWindowsService(options => options.ServiceName = "SMTP Telegram Gateway"); 25 | 26 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 27 | { 28 | LoggerProviderOptions.RegisterProviderOptions(builder.Services); 29 | } 30 | 31 | var host = builder.Build(); 32 | host.Run(); 33 | } 34 | } -------------------------------------------------------------------------------- /SmtpTelegramGateway/Program.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/7orlum/SmtpTelegramGateway/162b21a668cb41d4cb4de8e83fa4e623ed76fcac/SmtpTelegramGateway/Program.ico -------------------------------------------------------------------------------- /SmtpTelegramGateway/Smtp.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | using SmtpServer; 3 | using SmtpServer.Storage; 4 | 5 | namespace SmtpTelegramGateway; 6 | 7 | internal sealed class Smtp(MessageStore store, ILogger logger, IOptionsMonitor options) : BackgroundService 8 | { 9 | private SmtpServer.SmtpServer? _server; 10 | 11 | #pragma warning disable CA1031 // Do not catch general exception types 12 | protected override Task ExecuteAsync(CancellationToken stoppingToken) 13 | { 14 | try 15 | { 16 | var serverOptions = new SmtpServerOptionsBuilder() 17 | .Port(options.CurrentValue.SmtpPort) 18 | .Build(); 19 | 20 | var serviceProvider = new SmtpServer.ComponentModel.ServiceProvider(); 21 | serviceProvider.Add(store); 22 | 23 | _server = new SmtpServer.SmtpServer(serverOptions, serviceProvider); 24 | _server.SessionCreated += OnSessionCreated; 25 | _server.SessionCompleted += OnSessionCompleted; 26 | _server.SessionFaulted += OnSessionFaulted; 27 | _server.SessionCancelled += OnSessionCancelled; 28 | 29 | var result = _server.StartAsync(stoppingToken); 30 | 31 | return result; 32 | } 33 | catch (OperationCanceledException) 34 | { 35 | // When the stopping token is canceled, for example, a call made from services.msc, 36 | // we shouldn't exit with a non-zero exit code. In other words, this is expected... 37 | } 38 | catch (Exception ex) 39 | { 40 | logger.LogError(ex); 41 | 42 | // Terminates this process and returns an exit code to the operating system. 43 | // This is required to avoid the 'BackgroundServiceExceptionBehavior', which 44 | // performs one of two scenarios: 45 | // 1. When set to "Ignore": will do nothing at all, errors cause zombie services. 46 | // 2. When set to "StopHost": will cleanly stop the host, and log errors. 47 | // 48 | // In order for the Windows Service Management system to leverage configured 49 | // recovery options, we need to terminate the process with a non-zero exit code. 50 | Environment.Exit(1); 51 | } 52 | 53 | return Task.CompletedTask; 54 | } 55 | #pragma warning restore CA1031 // Do not catch general exception types 56 | 57 | public override async Task StopAsync(CancellationToken stoppingToken) 58 | { 59 | if (!stoppingToken.IsCancellationRequested && _server is not null) 60 | { 61 | _server.Shutdown(); 62 | await _server.ShutdownTask.ConfigureAwait(false); 63 | } 64 | 65 | await base.StopAsync(stoppingToken).ConfigureAwait(false); 66 | } 67 | 68 | private void OnSessionCreated(object? sender, SessionEventArgs e) 69 | { 70 | logger.LogSmtpSessionCreated(e); 71 | e.Context.CommandExecuting += OnCommandExecuting; 72 | } 73 | 74 | private void OnSessionCompleted(object? sender, SessionEventArgs e) 75 | { 76 | logger.LogSmtpSessionCompleted(e); 77 | e.Context.CommandExecuting -= OnCommandExecuting; 78 | } 79 | 80 | private void OnSessionCancelled(object? sender, SessionEventArgs e) 81 | { 82 | logger.LogSmtpSessionCancelled(e); 83 | e.Context.CommandExecuting -= OnCommandExecuting; 84 | } 85 | 86 | private void OnSessionFaulted(object? sender, SessionFaultedEventArgs e) 87 | { 88 | logger.LogSmtpSessionFaulted(e); 89 | e.Context.CommandExecuting -= OnCommandExecuting; 90 | } 91 | 92 | private void OnCommandExecuting(object? sender, SmtpCommandEventArgs e) 93 | { 94 | logger.LogSmtpCommandExecuting(e); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/SmtpTelegramGateway.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net9.0 4 | true 5 | true 6 | SmtpTelegramGateway.Program 7 | Program.ico 8 | 9 | latest 10 | enable 11 | enable 12 | true 13 | 14 | Pavel Veretennikov 15 | 16 | © 2024 Pavel Veretennikov 7orlum@gmail.com 17 | 3.0.0.0 18 | 3.0.0.0 19 | 3.0.0 20 | 21 | SmtpTelegramGateway 22 | en 23 | 24 | AllEnabledByDefault 25 | latest-all 26 | True 27 | True 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | PreserveNewest 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/Telegram.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | using MimeKit; 3 | using SmtpServer; 4 | using SmtpServer.Storage; 5 | using SmtpServer.Protocol; 6 | using System.Buffers; 7 | using Telegram.Bot; 8 | 9 | namespace SmtpTelegramGateway; 10 | 11 | internal sealed class Telegram(ILogger logger, IOptionsMonitor options) : MessageStore 12 | { 13 | private const string _asterisk = "*"; 14 | private TelegramBotClient? _bot; 15 | private string? _token; 16 | 17 | public override async Task SaveAsync( 18 | ISessionContext context, 19 | IMessageTransaction transaction, 20 | ReadOnlySequence buffer, 21 | CancellationToken cancellationToken) 22 | { 23 | try 24 | { 25 | using var stream = new MemoryStream(buffer.ToArray(), writable: false); 26 | using var message = await MimeMessage.LoadAsync(stream, cancellationToken).ConfigureAwait(false); 27 | var text = $"{message.Subject}\nFrom: {message.From}\nTo: {message.To}\n{message.TextBody}"; 28 | 29 | var currentOptions = options.CurrentValue; 30 | PrepareBot(currentOptions, cancellationToken); 31 | foreach (var chat in GetChats(currentOptions, message.To)) 32 | { 33 | logger.LogTelegramSendingMessage(chat); 34 | try 35 | { 36 | _ = await _bot!.SendMessage(chat, text, cancellationToken: cancellationToken).ConfigureAwait(false); 37 | } 38 | catch (OperationCanceledException) 39 | { 40 | throw; 41 | } 42 | catch (Exception e) 43 | { 44 | logger.LogError(e); 45 | } 46 | } 47 | 48 | return SmtpResponse.Ok; 49 | } 50 | catch (OperationCanceledException) 51 | { 52 | throw; 53 | } 54 | catch (Exception e) 55 | { 56 | logger.LogError(e); 57 | return SmtpResponse.TransactionFailed; 58 | } 59 | } 60 | 61 | private void PrepareBot(Configuration currentOptions, CancellationToken cancellationToken) 62 | { 63 | if (_bot != null && _token != currentOptions.TelegramBotToken) 64 | { 65 | _ = _bot.Close(cancellationToken); 66 | _bot = null; 67 | } 68 | 69 | if (_bot == null) 70 | { 71 | _bot = new TelegramBotClient(currentOptions.TelegramBotToken); 72 | _token = currentOptions.TelegramBotToken; 73 | } 74 | } 75 | 76 | private static IEnumerable GetChats(Configuration options, InternetAddressList emails) 77 | { 78 | var result = new List(); 79 | 80 | foreach (var address in emails) 81 | { 82 | switch (address) 83 | { 84 | case MailboxAddress email: 85 | var chats = options.Routing 86 | .Where(r => String.Equals(r.Email, email.Address, StringComparison.OrdinalIgnoreCase)) 87 | .Select(r => r.TelegramChat.Trim()) 88 | .ToArray(); 89 | 90 | if (chats.Length == 0) 91 | { 92 | chats = options.Routing 93 | .Where(r => r.Email == _asterisk) 94 | .Select(r => r.TelegramChat.Trim()) 95 | .ToArray(); 96 | } 97 | 98 | result.AddRange(chats); 99 | break; 100 | case GroupAddress group: 101 | result.AddRange(GetChats(options, group.Members)); 102 | break; 103 | default: 104 | throw new NotImplementedException(); 105 | } 106 | } 107 | 108 | return result.Distinct(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /SmtpTelegramGateway/appsettings.yaml: -------------------------------------------------------------------------------- 1 | # The port that the relay will listen on to receive SMTP e-mail messages, the default is 25. 2 | # No authorization is required when connecting to this port, 3 | # but if necessary, select the basic authentication method with a fake username and password 4 | SmtpPort: 25 5 | # Your token for the Telegram bot, get it at https://t.me/BotFather when registering the bot 6 | TelegramBotToken: SPECIFY THERE TELEGRAM BOT TOKEN 7 | # Define here a list of email addresses and telegram chats that will receive emails sent to these addresses. 8 | # Use an asterisk "*" instead of an email address to send all emails to some telegram chat 9 | # If you specify a Telegram user chat, the user must be subscribed to the bot 10 | # If you specify a Telegram group chat, you may need to add a minus sign prior to the group id, the bot must be added to the group 11 | # If you specify a Telegram channel chat, you may need to add -100 prior to the channel id, the bot must be added to the channel admins and given the right "Post in the channel" 12 | # For public channel chat, you can specify the channel public @username instead of the channel id 13 | Routing: 14 | - Email: "*" 15 | TelegramChat: SPECIFY THERE TELEGRAM USERID, GROUPID, CHANNELID OR @USERNAME 16 | - Email: example@test.com 17 | TelegramChat: SPECIFY THERE TELEGRAM USERID, GROUPID, CHANNELID OR @USERNAME 18 | # Logging Level. Set to Debug to see the details of the communication between your mail program and the relay. 19 | # Set to Error to see less information 20 | Logging: 21 | LogLevel: 22 | Default: Debug 23 | --------------------------------------------------------------------------------