I have purchased an authenticated SMTP package with my hosting company.
I have tested the account settings via Outlook 2010 successfully.
Outlook settings:
Email: me@domain.com Outgoing SMTP: smtp.hostingcompany.net
Logon Info:
- user: mydomain.com_account
- pass: password
More Settings > Outgoing Server:
- My Outgoing Server (SMTP) Requires authentication
- User: mydomain
- Pass: password
I have tried all possible combinations when specifying the NetworkCredentials and I keep getting an SMTP Exception: "Faulure Sending Email" InnerException: Invalid length for a Base-64 char array.
public static void SendEmail(string To, string Subject, string Body)
{
try
{
using (SmtpClient mySmtpClient = new SmtpClient(GlobalSettings.EmailHost))
{
mySmtpClient.UseDefaultCredentials = false;
//mySmtpClient.EnableSsl = false;
mySmtpClient.Credentials = new NetworkCredential(mydomain.com_account, GlobalSettings.EmailPassword);
MailAddress from = new MailAddress("email@mydomain");
MailAddress to = new MailAddress(To);
using (
MailMessage myMail = new MailMessage(from, to)
{
Subject = Subject,
SubjectEncoding = Encoding.UTF8,
Body = Body,
BodyEncoding = Encoding.UTF8,
IsBodyHtml = true
})
{
mySmtpClient.Send(myMail);
}
}
}
catch (SmtpException ex)
{
Log.WriteLog(string.Format("[Send Mail Exception] --> SMTPException has occurred: {0}", ex.Message), LogLevel.Error);
}
catch (Exception ex)
{
Log.WriteLog(string.Format("[Send Mail Exception] --> Exception has occurred: {0}", ex.Message), LogLevel.Error);
}
}
I have tried three possible username login parameters for the NetworkCredential().
Thanks in advance.
EDIT: NTLM Hack
I added the following lines to my code:
FieldInfo transport = _client.GetType().GetField("transport",
BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo authModules = transport.GetValue(_client).GetType()
.GetField("authenticationModules",
BindingFlags.NonPublic | BindingFlags.Instance);
Array modulesArray = authModules.GetValue(transport.GetValue(_client)) as Array;
modulesArray.SetValue(modulesArray.GetValue(2), 0);
modulesArray.SetValue(modulesArray.GetValue(2), 1);
modulesArray.SetValue(modulesArray.GetValue(2), 3);
I am now getting a new message:
Mailbox unavailable. The server response was: relay not permitted