DiskQuotaErrMaker


::: note
- 特定のメールボックスを容量超過させる必要があり作成したものです。
- 指定したメールアドレス宛に10MBの添付ファイルを指定回数分送信してDiskQuotaErrを発生させます。

- メールソフトで行おうと思いましたが10GBytes送る場合は1000回メールの操作をする必要が有り諦めました。
(1GBのファイルが送れれば良いがSMTPはそんな大サイズは送れない)
- 右下のボタンで稼働中と停止中の切り替えが可能。
- 宛先を間違えると大変な事になりますので使用は注意して下さい。
:::
<font COLOR="blue" >


### 1.起動画面</FONT>



![No1 - コピー.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821882/858dd5ff-c0d2-ca8d-5148-1dcc3bded805.jpeg)

 メークする前にソースヘッダ部のconst値を変えて下さい。
 fsutil.exe等で10MB程度のファイルを作り　AttPath=@"C:\10MB";　に指定。
<HR>
<font COLOR="blue" >

### 2.WPF (CSharp)
</FONT>

```C#
/////////////////////////////////////////
// MAILBOX DiskQuota Err Maker R1.00
// WPF(.NETFW) + Mailkit (nuget mailkit)
// (c)inf102 2024.
/////////////////////////////////////////

using MimeKit;
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace DiskQ {

    public partial class MainWindow : Window {

        //////////////////////////////////////////////////////////////////////////
        // パラメータ設定
        //////////////////////////////////////////////////////////////////////////
        
        // メール送信先 to
        const string MailToAddr="xxxx.ac.jp";

        // メール送信元 from
        const string MailFromAddr="xxxx.ac.jp";

        // SMTP PORTNo
        const int PortNo = 25;

        // SMTP ServerAddr
        const string SmtpAddr ="xxxx.ac.jp";

        // SMTP UsrName
        const string SmtpUsr ="xxxx";

        // SMTP Passwd
        const string SmtpPasswd="xxxx";

        // Att FILEFULLPATH
        const string AttPath=@"C:\10MB";

        // Wait (min)
        const int MinWait = 3;

        ////////////////////////////////////////////////////////////////////////
        // 内部使用静的
        // MAX Count
        static int MaxCnt = 0;

        // SendCounter
        static int SendCnt= 0;
        ////////////////////////////////////////////////////////////////////////

        public void TextUpdate() {
            DATTEXT.Text="添付ﾌｧｲﾙ....."+ AttPath +"\r\n送信間隔............"+MinWait+"分\r\n最大送信回数..."+MaxCnt.ToString()+"回\r\n送信回数............"+SendCnt.ToString()+"回";
        }

        public void LISTOUT(string s) {
            LIST1.Items.Add(s);         
            try {
                var border = VisualTreeHelper.GetChild(LIST1, 0) as Border;
                var listBoxScroll  = border.Child as ScrollViewer;
                listBoxScroll.ScrollToEnd();
            }catch{ }
        }

        public MainWindow() {
            InitializeComponent();

            ToAddr.Content  =MailToAddr;
            FromAddr.Content=MailFromAddr;
            TextUpdate();

            LISTOUT ("SMTP "+SmtpAddr);
            LISTOUT ("PORT "+PortNo.ToString());
            LISTOUT ("指定回数分、添付ﾌｧｲﾙを送信してﾒｰﾙﾎﾞｯｸｽの容量を\r\n超過させます.");
            LISTOUT ("------------------------------------------------------");
                         
            MainLoop();
        }

        public async void MainLoop() {
            DateTime dt = DateTime.Now;

            while(true) {
                await Task.Delay(10);
                if ((string)B1.Content == "停止中" ) continue;
                                     
                SendMAIL();
                SendCnt++;
                dt = DateTime.Now;
                LISTOUT (dt+" "+SendCnt.ToString() +"回目送信しました.");

                if (SendCnt >= MaxCnt ) {
                    LISTOUT ("送信完了しました.");
                    B1.Content= "完了" ;
                    B1.IsEnabled = false;
                    TextUpdate();
                    return;              
                }                           
                TextUpdate();
                await Task.Delay (MinWait*1000*60);
            }
        }

        public async void SendMAIL() {

            var message = new MimeKit.MimeMessage();
            message.From.Add(new MimeKit.MailboxAddress(MailFromAddr, MailFromAddr));
            message.To.Add(new MimeKit.MailboxAddress(MailToAddr, MailToAddr));
            message.Subject = "Making DISKQUOTA Err";

            var multipart = new MimeKit.Multipart ("mixed"){
                new MimeKit.TextPart (MimeKit.Text.TextFormat.Plain){
                    Text = "FROM DISKQUOTA Err Maker",
                },
                // 添付ファイルを設定
                new MimePart(MimeTypes.GetMimeType(AttPath)){
                    Content = new MimeContent(File.OpenRead(AttPath)),
                    ContentDisposition = new ContentDisposition(),
                    ContentTransferEncoding = ContentEncoding.Base64,
                    FileName = System.IO.Path.GetFileName(AttPath)
                }
            };

            message.Body = multipart;

            using (var client = new MailKit.Net.Smtp.SmtpClient()){
                try {
                    await client.ConnectAsync(SmtpAddr, PortNo);
                    await client.AuthenticateAsync(SmtpUsr, SmtpPasswd);
                    await client.SendAsync(message);
                    await client.DisconnectAsync(true);
                }
                catch (Exception ex){
                    LIST1.Items.Add (ex.Message);
                }
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e) {      
            if (MaxCnt==0 ) return;

            if ((string)B1.Content=="停止中") B1.Content="稼働中";
            else B1.Content ="停止中";
        }

        private void TEXT2_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) {
            if (MaxCnt==0) {
               return; 
            }
            try {
                MaxCnt=int.Parse(TEXT2.Text);
            }catch{ }

            SendCnt=0;
            TextUpdate();         
        }

        private void TEXT2_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) {
              e.Handled = !new Regex("[0-9]").IsMatch(e.Text);
               
        }

        private void textBoxPrice_PreviewExecuted(object sender, ExecutedRoutedEventArgs e){
            if (e.Command == ApplicationCommands.Paste){
                e.Handled = true;
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e) {
            if (TEXT2.Text=="") return;
            
            MaxCnt=int.Parse(TEXT2.Text);
            B3.IsEnabled = false;
            TEXT2.IsEnabled = false;

            TextUpdate();
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e) {
            Width=650;
            Height=345;
        }
    }
}

```
<font COLOR="blue" >

### 3.WPF (XAML)
</FONT>

``` xml

<Window x:Class="DiskQ.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DiskQ"
        mc:Ignorable="d" 
        Title="DiskQuotaErr Maker R1.00 " Height="345" Width="650" SizeChanged="Window_SizeChanged">
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="155*"/>
            <ColumnDefinition Width="208*"/>
            <ColumnDefinition Width="153*"/>
            <ColumnDefinition Width="134*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="44*"/>

            <RowDefinition Height="44*"/>
            <RowDefinition Height="127*"/>
            <RowDefinition Height="64*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4">
            <Border    BorderBrush="Black" Height="49"  >
                <TextBlock  Background="Beige" FontSize="34" Text="DiskQuotaErr Maker"  Foreground="DeepSkyBlue"  VerticalAlignment="Center" HorizontalAlignment="Center" Width="650" TextAlignment="Center" Height="48" />
            </Border>
        </StackPanel>

        <Label FontSize="22" Content="送信先" Margin="80,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Height="38" Width="84" />
        <Label FontSize="22" Content="送信元" Margin="80,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0"  Height="38" Width="84"/>
        <Label FontSize="28" x:Name="ToAddr"   Foreground="RED" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1"  Width="460" Height="45" VerticalAlignment="Center" FontFamily="Microsoft JhengHei UI" Grid.ColumnSpan="3" Margin="32,0,0,0"/>
        <Label FontSize="28" x:Name="FromAddr" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1"  Width="460" Height="45" VerticalAlignment="Center" FontFamily="Microsoft JhengHei UI" Grid.ColumnSpan="3" Margin="32,0,0,0"/>

        <TextBox x:Name="DATTEXT" FontSize="17" Grid.Column="2" Margin="1,3,4,3" Grid.Row="3"  TextWrapping="Wrap" Text="TextBox" Grid.ColumnSpan="2" IsReadOnly="True"  />
        <Button x:Name="B1" Grid.Column="3" Content="停止中" HorizontalAlignment="Center" Grid.Row="4" VerticalAlignment="Center" Height="40" Width="96" FontSize="20" Click="Button_Click" />
        <ListBox x:Name="LIST1" Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="0" Grid.RowSpan="2" Margin="4,3,3,3" FontSize="14" />

        <Label Grid.Column="2" FontSize="14" Content="回数" HorizontalAlignment="Left" Margin="-4,0,0,0" Grid.Row="4" VerticalAlignment="Center" Height="28" />
        <TextBox x:Name="TEXT2" Grid.Column="2" HorizontalAlignment="Left" FontSize="22" Margin="33,0,0,0" Grid.Row="4" CommandManager.PreviewExecuted="textBoxPrice_PreviewExecuted"  VerticalContentAlignment="Center"  VerticalAlignment="Center" Width="63" Height="33" KeyUp="TEXT2_KeyUp" PreviewTextInput="TEXT2_PreviewTextInput" />
        <Button x:Name="B3" Grid.Column="2" Content="設定" HorizontalAlignment="Left" Margin="99,0,0,0" Grid.Row="4" VerticalAlignment="Center" FontSize="16" Click="Button_Click_1" Width="49" Height="26"/>

    </Grid>
</Window>

```