備忘録

備忘録

PostfixでYahooメールにリレーする方法

Ⅰ. はじめに

タイトルの通り「PostfixでYahooメールにリレーする方法」です。

Ⅱ. 環境

$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

Ⅲ. Postfix の設定

1. main.cf ファイルに以下を追記する
$ vim /etc/postfix/main.cf
transport_maps = hash:/etc/postfix/transport

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/password_maps
smtp_sasl_security_options = noanonymous
2. transport ファイルを編集する
$ vim /etc/postfix/transport
*       smtp:[smtp.mail.yahoo.co.jp]:587
3. password_maps ファイルを編集する
$ vim /etc/postfix/password_maps
[smtp.mail.yahoo.co.jp]:587     usre_name@yahoo.co.jp:password
4. データベースを再構築する
postmap hash:/etc/postfix/transport
postmap hash:/etc/postfix/password_maps
5. Postfix の設定をリロードする
$ service postfix restart

Ⅳ. telnet を利用してテストメールを送信する

$ telnet localhost smtp
# ctrl + ] を押す
telnet> toggle crlf

HELO localhost
MAIL FROM: user_name@yahoo.co.jp
RCPT TO: xxx@gmail.com
DATA
Subject: Hello!
This is a test mail.
.

QUIT

C#でPowerPoint(ppt, pptx)ファイルから文字列を抽出する方法

Ⅰ. はじめに

タイトルの通り「C#PowerPoint(ppt, pptx)ファイルから文字列を抽出する方法」です。

Ⅱ. やり方

1. サンプルファイルを用意する

http://www.mediafire.com/file/b66k4kxskc2agl1/sample.pptx/file
f:id:kagasu:20190201182119p:plain

2. 参照を追加する

画像の2つのCOM参照を追加する事で「Microsoft.Office.Core」と「Microsoft.Office.Interop.PowerPoint」が追加されます。
f:id:kagasu:20190201182006p:plain

3. サンプルプログラムを書く
using System;
using Microsoft.Office.Core;
using PPT = Microsoft.Office.Interop.PowerPoint;

namespace GetPowerPointText
{
  class Program
  {
    static void Main(string[] args)
    {
      var file = new PPT.Application().Presentations.Open("c:\\sample.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
      var slideCount = file.Slides.Count;
      Console.WriteLine($"スライド数:{slideCount}");

      foreach (PPT.Shape shape in file.Slides[1].Shapes)
      {
        if (shape.HasTextFrame == MsoTriState.msoTrue)
        {
          if (shape.TextFrame.HasText == MsoTriState.msoTrue)
          {
            Console.WriteLine(shape.TextFrame.TextRange.Text);
          }
        }
        else if (shape.HasTable == MsoTriState.msoTrue)
        {
          // インデックスを指定する場合
          // Console.WriteLine(shape.Table.Columns[2].Cells[3].Shape.TextFrame.TextRange.Text);
          foreach (PPT.Column column in shape.Table.Columns)
          {
            foreach (PPT.Cell cell in column.Cells)
            {
              Console.WriteLine(cell.Shape.TextFrame.TextRange.Text);
            }
          }
        }
      }
      file.Close();
    }
  }
}

実行結果

f:id:kagasu:20190201182625p:plain

Node.jsでMariaDB, MySQLを扱う方法

Ⅰ. はじめに

タイトルの通り「Node.jsでMariaDB, MySQLを扱う方法」です。

Ⅱ. やり方

1. 必要なパッケージをインストールする
npm install mysql2
2. サンプルプログラムを書く
const mysql = require('mysql2');
const util = require('util');

(async () => {
  const pool = mysql.createPool({
    connectionLimit: 10,
    host: '127.0.0.1',
    user: 'user',
    password: 'my_password',
    database: 'my_database'
  })

  pool.query = util.promisify(pool.query)

  // SELECTする
  let results = await pool.query('select * from accounts')
  console.log(results)

  // INSERTする
  let data = { id: 2, name: 'name002' }
  await pool.query('insert into accounts set ?', data)

  // SELECTする(INSERTできたか確認する)
  results = await pool.query('select * from accounts')
  console.log(results)

  pool.end()
})()
実行結果
[ RowDataPacket { id: 1, name: 'name001' } ]

[ RowDataPacket { id: 1, name: 'name001' },
  RowDataPacket { id: 2, name: 'name002' } ]

Vue.js + Bulma で ハンバーガーメニューをトグルする方法

はじめに

タイトルの通り「Vue.js + Bulma で ハンバーガーメニューをトグルする方法」です。

DockerをLinuxにインストールする方法

Ⅰ. はじめに

タイトルの通り「DockerをLinuxにインストールする方法」です。

Ⅱ. やり方

1. Docker をインストールする
source <(curl -s https://get.docker.com/)
2. Docker を起動する
systemctl enable docker
systemctl start docker
3. Docker でhello worldする
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
4. hello-world を削除する(任意)
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        2 weeks ago         1.84kB

$ docker rmi -f fce289e99eb9
Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e