简体   繁体   中英

Smtp Client C# Problem with Aruba PEC and with attachment

this is my code:

try {
SmtpClient client = new SmtpClient("smtp.aruba.it", 25);
                        client.EnableSsl = true;
                        client.Timeout = 10000;
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials = new NetworkCredential("receiver@pec.it", "password");
                        MailMessage msg = new MailMessage();
                        msg.To.Add("receiver@pec.it"); //Receiver
                        msg.From = new MailAddress("sender@pec.it"); //Sender
                        msg.Subject = "Object"; //Oggetto Mail
                        msg.Body = ""; //Corpo del testo
                        Attachment data = new Attachment(fileName);
                        msg.Attachments.Add(data);
                        client.Send(msg);
                        MessageBox.Show("Attachment send correctly");
                    }
                    catch (SmtpException ex)
                    {
                        throw new ApplicationException
                          ("SmtpException has occured: " + ex.Message);
                    }

I tried to use this code but it doesn't work. I tried with gmail host and it works, so the code should work. The problem is smtp for sure but I couldn't find the right way to send it via pec aruba. Another problem is the attachment. The name of attachment is the entire filename path and i want that is only the name of the file. How i can resolve this two problem?

Use smtps.aruba.it instead smtp.aruba.it and port 587. It works for me ( I had same problem)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM