PDA

View Full Version : سوال: Drag and Drop و multiattach



قله بلند
جمعه 29 اسفند 1393, 12:18 عصر
با عرض سلام
من یک لیست باکس روی فرم گذاشته ام و با درگ و دارپ، فایل ها رو به درونش می کشم. از هر فایل، دو تا آدرس ذخیره می شه (چرا؟). چه طوری می تونم چند اتچی داشته باشم؟ برنامه با خطا متوقف می شه و خطای The operation timed out رو صادر می کنه.



private void button_SendEmail_Click(object sender, EventArgs e)
{
string tempP =My Gmail Password;
System.Security.SecureString password = new System.Security.SecureString();

tempP.ToCharArray().ToList().ForEach(p => password.AppendChar(p));

string mailfrom = textBox_From.Text;
string mailto = textBox_To.Text; ;
string subject =textBox_Subject.Text;
string body = richTextBox_Body.Text;

using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(mailfrom, "ARZ", System.Text.Encoding.UTF8);
mail.To.Add(mailto);
mail.Subject = subject;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = body;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.Priority = MailPriority.High;
mail.IsBodyHtml = true;

// Can set to false, if you are sending pure text.

for (int i = 0; i < (listBox_1.Items.Count); i++)
{
MessageBox.Show(listBox_1.Items.Count.ToString());
string tempL = listBox_1.Items[i].ToString();
MessageBox.Show(tempL);
mail.Attachments.Add(new Attachment(tempL));
}

using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(mailfrom, password);
smtp.EnableSsl = true;
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}







private void listBox_1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.All;
else e.Effect = DragDropEffects.None;
}

private void listBox_1_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop,false);
int i;
string tempL="";
foreach (string filepath in files)
{
tempL = filepath;
}
for (i = 0; i < files.Length; i++)
{
listBox_1.Items.Add(tempL);
}
}