I'm trying to send a message to an internal SMTP server using anonymous.
My understanding is that I should only need to remove the client.Authenticate(SmtpUserID, SmtpPassword); call to send it via anonymous.
I keep getting the following error : Client was not authenticated (530).
Code example:
[code lang='c#']
// Create a new instance of the SmtpClient class.
using (SmtpClient client = new SmtpClient())
{
try
{ // Connect to the server.
client.Connect(SmtpServerAddress, SmtpPort);
// test for anonymous login
if (!String.IsNullOrEmpty(SmtpUserID))
{
client.Authenticate(SmtpUserID, SmtpPassword);
}
// Create a new mail message.
MailMessage msg = new MailMessage();
msg.Subject = @subjectStr;
msg.Priority = Priority;
msg.BodyText = @bodyStr;
msg.From.Add(SmtpFromUserID);
msg.To.Add(toAddress);
if (fileAttachment != null)
{
msg.Attachments.Add(fileAttachment);
}
client.Send(msg);
client.Disconnect();
ReportLog(trfid, msgStr, EventLogEntryType.Information, 1000, Actions.Internal);
}
catch (SmtpException ex)
{
....
}
}
[/code]