This is in my new class top:
MailMessage photosmessage;
This is the method i have in my new class:
public void SendPhotos(string fileNameToSend)
{
try
{
MailAddress from = new MailAddress("[email protected]", "User " + (char)0xD8 + " Name",
System.Text.Encoding.UTF8);
MailAddress to = new MailAddress("MyEimalOfMyInternet");
photosmessage = new MailMessage(from, to);
photosmessage.Body = "Please check the log file attachment i have some bugs.";
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
photosmessage.Body += Environment.NewLine + someArrows;
photosmessage.BodyEncoding = System.Text.Encoding.UTF8;
photosmessage.Subject = "Log File For Checking Bugs" + someArrows;
photosmessage.SubjectEncoding = System.Text.Encoding.UTF8;
Attachment myAttachment = new Attachment(fileNameToSend, MediaTypeNames.Application.Octet);
photosmessage.Attachments.Add(myAttachment);
SmtpClient docsend = new SmtpClient("smtp.gmail.com", 587);
docsend.SendCompleted += new SendCompletedEventHandler(docsend_SendCompleted);
docsend.EnableSsl = true;
docsend.Timeout = 10000;
docsend.DeliveryMethod = SmtpDeliveryMethod.Network;
docsend.UseDefaultCredentials = false;
docsend.Credentials = new NetworkCredential("gmailusername", "gmailpassword");
string userState = "test message1";
docsend.SendAsync(photosmessage, userState);
SendLogFile.Enabled = false;
}
catch (Exception errors)
{
Logger.Write("Error sending message :" + errors);
}
}
Im using this method in Form1 like this:
se.SendPhotos(outputtext+"\\"+"textfiles.zip");
se.SendPhotos(outputphotos + "\\" + "photofiles.zip");
Firsrt time its sending zipped file of some text files inside the zip file is about 5kb Sending the zip file no problems.
Then its sending a zip file of 19mb that inside there are some images/photos each photos about 7.55mb This time the zip file never get to my email.
The first zip file of the text files i get it but the second one i never get it. Im using my gmail email account to send this files to my regular isp email account.
I know in gmail you cant send more then 25mb but the zip file of the photos is 19mb
What else could be the reason i never get the second zip file ?
Edit:
I think i know what is the problem. When getting and creating the zip of text file i did a filter ".txt" but when doing it with the photos zip file i did ".*" all the files:
string[] photosfiles = Directory.GetFiles(s, "*.*", SearchOption.AllDirectories);
The result is i had a file with .ini in the zip file.
How can i filter for all images types ?
string[] photosfiles = Directory.GetFiles(s, "*.jpg", SearchOption.AllDirectories);
This will work for jpg files only but if i want also to get png or bmp ?
For the added question (in your Edit
), you can use the following code to get all the files you want:
string[] extensions = {"*.bmp","*.jpg","*.png", "*.gif" };//add extensions you want to filter first
var filenames = extensions.SelectMany(x => Directory.GetFiles(s, x));
Hope it helps.