The following code nets me out error after error.
MailMessage Enveloppe = new MailMessage();
//emails is an array of strings
foreach ( string email in emails )
Enveloppe.To.Add(email);
//Setup message parameters
Enveloppe.Subject = "Documentation";
Enveloppe.Body = "Infinitelycoolbodyhere"
Enveloppe.From = new MailAddress("mrzombie@stuff", "Myname");
//files is an array of strings
foreach ( string filename in files ) {
//Add attachments
Enveloppe.Attachments.Add(new Attachment(new System.Net.WebClient().OpenRead(filename),filename.Substring(filename.LastIndexOf('/'))));
}
//Create the smtp client, and let it do its job
SmtpClient Mailman = new SmtpClient("mysmtphost");
Mailman.EnableSsl = true;
Mailman.Port = 465;
Mailman.DeliveryMethod = SmtpDeliveryMethod.Network;
Mailman.Credentials = new System.Net.NetworkCredential("usernamehere", "passwordhere");
Mailman.Send(Enveloppe);
It so happens that it either tells me that my operation timed out, or that “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”.
I’m stumped, I don’t see which part of it I am doing wrong
Update: I can’t seem to connect to the server from Telnet, at best I connect with my laptop (under ubuntu), but I never get the “200” response. Under the windows workstation, I get a perpetual blank telnet window.
I can send/receive e-mail at the specified server with Thunderbird without any problem whatsoever.
Finally found the culprit – somehow the connection was left hanging between the “supposedly correct” smtp server the hosting company was giving me, and the actual smtp server. I just changed the address of mail.domain.com to smtp.hostingdomain.com and it fixed everything.
This is just one of those “what the hell” moments that I hate. Because of it, I had to drop the feature of application-based mail-sending, but in the end my boss and I decided that we’d instead host the files somewhere and include the links in the e-mail instead of appending attached files to the mail.
So, yeah, that doesn’t really answer the question, but to those who consider the solution, but you might want to put the files you want to send on a place accessible from the outside and include linkage instead. There.