# ============================================================= # Quink Upload & Email Notify サンプルスクリプト (PowerShell / EXE 不要) # # ファイルをアップロードして、発行された URL をメールで送信します。 # # 使い方: # .\upload_and_notify.ps1 -To "recipient@example.com" -Files "C:\report.zip" # .\upload_and_notify.ps1 -To "recipient@example.com" -Files "C:\a.zip","C:\b.pdf" # # 前提: # Windows 10 1803 以降(curl.exe が標準搭載) # ============================================================= param( [Parameter(Mandatory = $true)] [string]$To, [Parameter(Mandatory = $true)] [string[]]$Files ) # ── Quink 設定 ──────────────────────────────────────────────── $API_KEY = "your-api-key-here" # マイファイルページで取得した API キー $UPLOAD_URL = "https://quink.jp/upload" # ── SMTP 設定(ここを編集してください) ────────────────────── # ※ ポート 587(STARTTLS)対応。 # ポート 465(SSL 直接)を使う場合は Mac 版の upload_and_notify.sh をご利用ください。 $SMTP_HOST = "smtp.example.com" $SMTP_PORT = 587 $SMTP_USER = "sender@example.com" $SMTP_PASS = "your-smtp-password" $MAIL_FROM = "sender@example.com" # ───────────────────────────────────────────────────────────── # ── アップロード ────────────────────────────────────────────── $urlList = @() foreach ($f in $Files) { if (-not (Test-Path $f)) { Write-Warning "ファイルが見つかりません(スキップ): $f" continue } Write-Host "Uploading: $(Split-Path $f -Leaf)" -ForegroundColor Cyan $response = curl.exe -s -X POST $UPLOAD_URL ` -H "X-API-Key: $API_KEY" ` -F "file=@`"$f`"" try { $json = $response | ConvertFrom-Json if ($json.url) { Write-Host " -> $($json.url)" -ForegroundColor Green $urlList += $json.url } else { $detail = if ($json.detail) { $json.detail } else { $response } Write-Warning " [ERROR] $(Split-Path $f -Leaf): $detail" } } catch { Write-Warning " [ERROR] $(Split-Path $f -Leaf): $response" } } if ($urlList.Count -eq 0) { Write-Host "[ERROR] アップロードに成功したファイルがないため、メールは送信しません。" -ForegroundColor Red exit 1 } # ── メール本文を組み立て ────────────────────────────────────── $subject = if ($urlList.Count -eq 1) { "ファイルを共有しました" } else { "ファイルを $($urlList.Count) 件共有しました" } $urlBlock = ($urlList | ForEach-Object { " $_" }) -join "`r`n" $mailBody = @" ファイルをアップロードしました。 ダウンロードリンクよりお受け取りください。 $urlBlock ※ リンクには有効期限があります。お早めにダウンロードをお願いします。 "@ # ── メール送信 ──────────────────────────────────────────────── Write-Host "" Write-Host "Sending email to: $To" -ForegroundColor Cyan try { $smtp = New-Object System.Net.Mail.SmtpClient($SMTP_HOST, $SMTP_PORT) $smtp.EnableSsl = $true $smtp.Credentials = New-Object System.Net.NetworkCredential($SMTP_USER, $SMTP_PASS) $msg = New-Object System.Net.Mail.MailMessage $msg.From = $MAIL_FROM $msg.To.Add($To) $msg.Subject = $subject $msg.Body = $mailBody $msg.BodyEncoding = [System.Text.Encoding]::UTF8 $smtp.Send($msg) $msg.Dispose() Write-Host "メールを送信しました -> $To" -ForegroundColor Green } catch { Write-Error "メール送信失敗: $($_.Exception.Message)" exit 1 }