【问题标题】:Smtp Client C# Problem with Aruba PEC and with attachmentAruba PEC 和附件的 Smtp 客户端 C# 问题
【发布时间】:2021-06-21 21:42:49
【问题描述】:

这是我的代码:

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);
                    }

我尝试使用此代码,但它不起作用。我尝试使用 gmail 主机并且它可以工作,所以代码应该可以工作。问题肯定是 smtp,但我找不到通过 pec aruba 发送它的正确方法。 另一个问题是附件。附件的名称是整个文件名路径,我希望这只是文件的名称。我该如何解决这两个问题?

【问题讨论】:

标签: c# smtpclient


【解决方案1】:

使用 smtps.aruba.it 代替 smtp.aruba.it 和端口 587。它对我有用(我有同样的问题)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 2011-09-30
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 2010-12-26
    相关资源
    最近更新 更多