ASP.net SMTP server connection error
The following code disables 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 just so happens that this either tells me that my operation has completed, or that "the connection attempt failed because the related party did not respond properly after some time, or the connection failed because the connected host was unable to respond."
I'm stumped, I can't see which part of it I'm doing wrong
Update: I cannot connect to the server from Telnet, at best I connect to my laptop (under ubuntu), but I never get a "200" response. Under Windows workstation, I get a perpetually blank telnet window.
I can send / receive email on a specified server with Thunderbird without any problem.
a source to share
Finally I found the culprit - for some reason, the connection remained dangling between the "supposedly correct" smtp server, which was provided to me by the hosting company, and the actual smtp server. I just changed the mail.domain.com address to smtp.hostingdomain.com and it fixed everything.
This is just one of those moments that I hate. Because of this, I had to abandon the app-based sending mail feature, but in the end, my boss and I decided that we would instead host files and include links in email instead of adding attachments to the mail.
So yes, that doesn't really answer the question, but for those considering a solution, but you might want to put the files you want to send to an externally accessible location and include a link instead. There.
a source to share
It looks like something went wrong when you try to contact your SMTP server (haha, no, shit!).
I assume you are on windows, go to Start -> Run -> 'telnet mysmtphost 465' and see the response you get in the console.
Do you see something like this?
Connected to mysmtphost.
Escape character is '^]'.
220 mysmtphost
a source to share
Try enabling tracing for System.Net.Mail (looks like you are using SNM). To do this, you need to add the following to your .config file.
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net" >
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="MyTraceFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log" />
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
</switches>
Hopefully this should at least tell you what's going on.
I have some more information here on what to expect: http://systemnetmail.com/faq/4.10.aspx
a source to share