[�z�[��] [��ЊT�v] [���i] [�T�|�[�g]
[BASP21 Pro] [FAQ] [�A�v���P�[�V�����K�C�h] [���[�U�K�C�h] [���t�@�����X] [�T���v��]
[FTP �I�u�W�F�N�g] [�\�P�b�g �I�u�W�F�N�g]

BASP21 Pro Office365 SMTP/POP3 OAuth2�F�� (SendMail/RcvMail)

SendMail/RcvMail���\�b�h��Office365 OAuth2�F�؂ŃA�N�Z�X������@��������܂��B

OAuth2�F�؂�SendMail/RcvMail���\�b�h�����s����ɂ͈ȉ��̎菇���K�v�ł��B

Azure AD �ɂ���Ē񋟂����OAuth�F�؃T�[�r�X���g�p���āA BASP21 Pro ��SMTP/POP�v���g�R�����g�p���ă��[���𑗎�M���邱�Ƃ��ł��܂��B

basp21p.ini�p�����[�^�́A�ȉ��̂悤�ɐݒ肪�K�v�ł��B
basp21p.ini�p�����[�^���O����
client_id�N���C�A���gID�N���C�A���gID
client_secret�N���C�A���g�V�[�N���b�g�N���C�A���g�V�[�N���b�g
refresh_token���t���b�V���g�[�N�����t���b�V���g�[�N��
token_uri�A�N�Z�X�g�[�N���擾URLOAuth 2.0 �g�[�N�� �G���h�|�C���g (v2)
https://login.microsoftonline.com/�i�e�i���gID�j/oauth2/v2.0/token
serveroffice365 SMTP�T�[�o�[Smtp.office365.com
TLS Smtp.office365.com:587
mailfromMailFrom���M�����[���A�h���X,office365�A�J�E���g�FXOAUTH2
popserveroffice365 POP�T�[�o�[Outlook.office365.com:995



basp21p.ini�t�@�C���ɐݒ肪�K�v�ȃp�����[�^���擾���邽�߂� ���F�G���h�|�C���g/�g�[�N���G���h�|�C���g���ďo���܂��B
���̍ۂɃR�}���h�v�����v�g�� curl �R�}���h���g���܂��B
curl �R�}���h�́AWindows 10�ɕW���C���X�g�[������Ă��܂��B
�R�}���h�v�����v�g�� curl -V �Ŋm�F�ł��܂��B

C:\>curl -V
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Release-Date: [unreleased]
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL

C:\>
�C���X�g�[������ĂȂ��ꍇ�́A�C���X�g�[�����K�v�ł��B
�Q�l�F curl�̃C���X�g�[��

���FBASP21 Pro �̎��s�ɂ́Acurl �R�}���h�͎g���܂���B
curl�́AAzure AD����OAUth2�p�����[�^�擾�ɕK�v�ł��B


�Q�l�F OAuth ���g�p���� IMAP�APOP�A�܂��� SMTP �ڑ���F�؂���

�d�v�F Azure AD �����s����g�[�N���̗L�����Ԃɂ‚���
�X�V�g�[�N���̗L��������90���ł��B
�X�V�g�[�N���̗L���������؂��ƈȉ��̂悤�ȃG���[�Ń��\�b�h�����s���܂��B
-86	OAUTH2�F�؃G���[�B

(���O)
2020/11/02 16:20:07.216 3948-6294376 office365(32bit WOW64) RcvMail HTTP > POST /a7a81c19-a273.....
2020/11/02 16:20:07.528 3948-6294376 office365(32bit WOW64) RcvMail HTTP < HTTP/1.1 400 Bad Request
2020/11/02 16:20:07.528 3948-6294376 office365(32bit WOW64) RcvMail ERROR:-52 [SYSTEM]server error HTTP/1.1 400 Bad Request
2020/11/02 16:20:07.528 3948-6294376 office365(32bit WOW64) RcvMail end -86  (842msec)

�g�[�N���T�[�o�[�̃A�N�Z�X��HTTP 400�G���[�ƂȂ�܂��B


�Q�l�F Microsoft ID �v���b�g�t�H�[���ł̍\���”\�ȃg�[�N���̗L������ (�v���r���[)

office365 OAuth2�F�؂́A�o�[�W���� 1,0,2007,17�ȍ~�ŃT�|�[�g����܂��B

�� Azure AD�A�v���P�[�V������o�^[�N���C�A���gID]��[�N���C�A���g�V�[�N���b�g]�擾(�u���E�U)

[�N���C�A���gID]��[�N���C�A���g�V�[�N���b�g]�́A�u���E�U���g���Ď擾���܂��B
Azure Portal�Ƀ��O�C�����āA�A�v���P�[�V�����o�^���܂��B

1. �A�v���P�[�V�����̓o�^�B
�C�ӂ̖��O�ł��܂��܂���B

���_�C���N�gURL�Bhttp://localhost/myapp/�B



2. �N���C�A���gID�ƃe�i���gID���R�s�[�B




3. �N���C�A���g�V�[�N���b�g�쐬���R�s�[
�C�ӂ̐����B�C�ӂ̗L�������B�lj����N���b�N�B
�����łP�N��Q�N���w�肷��Ɗ������ BASP21 Pro ���[���ɂ��SMTP/POP3 �A�N�Z�X�����s���܂��B
���̏ꍇ�A�V�K�ɃN���C�A���g�V�[�N���b�g�쐬���āA ���F�G���h�|�C���g����[�F�؃R�[�h]���擾����K�v������܂��B




�V�[�N���b�g���R�s�[���܂��B



4. API�̃A�N�Z�X���‚̒lj�
[API�̃A�N�Z�X����]-[�A�N�Z�X���‚̒lj�]���N���b�N�B




[Microsoft Grapf]-[�ϔC���ꂽ�A�N�Z�X����]���N���b�N�B




�ȉ��̂R�‚�I�����Ēlj����܂��B


API�A�N�Z�X���‚̗v���I����@�́A[�A�N�Z�X���‚�I������]�e�L�X�g�{�b�N�X�ɁAOFF  �ŃG���^�[�L�[�A
�@�@offline_access
�@�@Maintain access to data you have given it access to
��I���B

����
POP�@�ŃG���^�[�L�[�A
�@�@POP.AccessAsUser.All
�@�@Read and write access to mailboxes via POP.
��I���B

����SMTP ����͂���
�@�@SMTP.Send
�@�@Send emails from mailboxes using SMTP AUTH.
��I�����܂��B





�� ���F�G���h�|�C���g����[�F�؃R�[�h]���擾(�u���E�U)

[�F�؃R�[�h]�́A�c�[���ƃu���E�U���g���Ď擾���܂��B
���̏����́A�Ď擾���K�v�ɂȂ����Ƃ��A���s���K�v�ł��B

�c�[��(office365-oauth2.vbs �t�@�C��)�̃_�E�����[�h�́A ������B

�g�p����scope �́A�ȉ��̒ʂ�ł��B
POP ..... https://outlook.office.com/POP.AccessAsUser.All
SMTP .... https://outlook.office.com/SMTP.Send

1. �c�[���ŔF�؃R�[�h���擾
office365-oauth2.vbs �t�@�C�����G�f�B�^�ŊJ���āA���������𖄂ߍ��݂܂��B


office365-oauth2.vbs�@�t�@�C���̓��e�B
''==============================================
'' ���O�t�@�C���Z�b�g
LOGFILE="C:\����slog.txt"
'' curl �g���[�X�t�@�C���Z�b�g
CURLTRACE1="--trace-ascii C:\����clog1.txt"
CURLTRACE2="--trace-ascii C:\����clog2.txt"

'�N���C�A���gID���Z�b�g
CID="����"
'�N���C�A���g�V�[�N���b�g���Z�b�g
CSS="����"
'�e�i���gID���Z�b�g
TID="����"
'==============================================

office365-oauth2.vbs �t�@�C�����_�u���N���b�N���Ď��s���܂��B


2.�F�؃R�[�h�擾
�u���E�U�������N�����܂��̂ŔF�؃R�[�h���擾���܂��B

�u���E�U��URL��@���Ɠ��Ӊ�ʂ��\������܂��B
�g�p����A�J�E���g��I���B
���̂Ƃ��ABASP21 Pro �Ŏg�����[���A�h���X�ŔF�؂��Ă��������B

�c�[���ōēx�A�F�؃R�[�h�擾�����蒼���ꍇ�́A �ȉ��̂悤��2�‚̕ϐ����N���A���Ă��������B

office365-oauth2.vbs�@�t�@�C���̓��e�B
'' �ϐ��N���A
ACC=""
REF=""




[����]���N���b�N�B




�u���E�U��URL�����ŕ\�������F�؃R�[�h���R�s�[���āA office365-oauth2.vbs �t�@�C�����ɃZ�b�g���܂��B
?code=xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxx�̕����ł��B

office365-oauth2.vbs�@�t�@�C���̓��e�B

' �t�F�[�Y