E -Mail aus Windows -Dienst senden: Die Transaktion ist fehlgeschlagen. Die Serverantwort war 5.7.1 Client -Host AbgelehC#

Ein Treffpunkt für C#-Programmierer
Guest
 E -Mail aus Windows -Dienst senden: Die Transaktion ist fehlgeschlagen. Die Serverantwort war 5.7.1 Client -Host Abgeleh

Post by Guest »

Der folgende Code funktioniert gut aus Windows -Formular, aber nicht von Windows Services.
Der Dienst wird unter Windows XP ausgeführt. Ändern des Protokolls auf Benutzer, jedoch nicht funktioniert. Die Serverantwort war 5.7.1 Client -Host
abgelehnter Zugriff verweigert < /p>
< /blockquote>

Code: Select all

private void SendEmailToHO()
{
try
{
int mailSentSuccessfully = 0;

MailAddress to = new MailAddress(mailTo);
MailAddress from = new MailAddress(mailFrom);

using (MailMessage mail = new MailMessage(from.Address, to.Address))
{

int attachmentCount = 0;

try
{
foreach (string fileName in fileEntries)
{
Attachment attachment = new Attachment(fileName);
mail.Attachments.Add(attachment);
attachmentCount++;
}

SmtpClient client = new SmtpClient(mailHost, port);
if (enableSSL == "Y")
{
client.EnableSsl = true;
}
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(mailUser, mailPassword);

mail.Subject = "Email Subject " + clientID;
mail.Body = "Attached please find the files: " + clientIDTitle;

if (attachmentCount > 0)
{
//
client.Send(mail);

//if no error, this code will work.
mailSentSuccessfully = 1;

new MyApp.LogWriter("Sent mail to " + to.Address + ", \nAttachment count = " + attachmentCount);
}
else
{
new MyApp.LogWriter("Attachment count = " + attachmentCount);
}
}
catch (Exception ex)
{
new MyApp.LogWriter("Send mail failed. Cause: " + ex.Message
+ "\n Inner Exception: " + ex.InnerException);
}
}
}
catch (System.Exception ex)
{
new BTCClient.LogWriter("Email Error '" +
ex.Message + "'");
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post