7orlum / SmtpTelegramRelay

Аn SMTP gateway transferring emails directly to the Telegram bot
MIT License
7 stars 4 forks source link

Unhandled Exception: System.ArgumentException: Invalid format. A valid token looks like "1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy" #1

Closed francescoemme closed 2 years ago

francescoemme commented 2 years ago

Hello the program is crashing on startup with the message

Unhandled Exception: System.ArgumentException: Invalid format. A valid token looks like "1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy"

using a token for a bot just created. The program does not crash using the sample token 1234.. but of course it's not that useful Thanks Francesco

7orlum commented 2 years ago

Hello, Francesco Let me please take a look at your SmtpTelegramRelay.exe.config. It must be like

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="telegramSettings" type="SmtpTelegramRelay.TelegramConfiguration,SmtpTelegramRelay" />
    <section name="smtpSettings" type="SmtpTelegramRelay.SmtpConfiguration,SmtpTelegramRelay" />
  </configSections>

  <telegramSettings token="1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy" chatId="20000003" />
  <smtpSettings port="25" />

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

For security reason you will have to revoke your bot current API token through https://t.me/botfather after that.

Best regards, Pavel

francescoemme commented 2 years ago

Hello Pavel thanks for the swift reply. Here is my config file This is just a test bot


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="telegramSettings" type="SmtpTelegramRelay.TelegramConfiguration,SmtpTelegramRelay" />
    <section name="smtpSettings" type="SmtpTelegramRelay.SmtpConfiguration,SmtpTelegramRelay" />
  </configSections>

  <telegramSettings token="5001559278:AAHDf4rpUHO3wu1uBps_OsgJvW6IXnT9qTw" chatId="MY_CHAT_ID" />
  <smtpSettings port="25" />

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Thanks Best Regards Francesco

7orlum commented 2 years ago

Francesco, I've just published a new version that must fix your problem. Try it please https://github.com/7orlum/SmtpTelegramRelay/releases/tag/v1.3 Best regards, Pavel

francescoemme commented 2 years ago

Hi Pavel tested, the program is not crashing anymore and I'm getting the message on Telegram. I'm not getting the full email, just

From: pippo@local To:

but this might be due to the fact that the mailer I'm using (msmtp) is not including the To: field in the DATA part, see capture below; anyway for my purpose I just need the notification, don't care about the actual content. Thanks Francesco

220 v9.0.1.0 ESMTP ready EHLO localhost 250- Hello localhost, haven't we met before? 250-PIPELINING 250-8BITMIME 250 SMTPUTF8 MAIL FROM:pippo@local 250 Ok RCPT TO:test@exampl43.com DATA 250 Ok 354 end with . From: pippo@local Date: Sun, 05 Dec 2021 18:01:35 +0100 hello world . 250 Ok QUIT 221 bye