[Mono-list] SmtpClient.Send failing with Argument out of range SmtpException
yakpimp
kmcgrail at gmail.com
Wed Nov 20 17:53:01 UTC 2013
I'm having an issue with an application I wrote a while back which I
originally was running on windows. I wanted to run it on my Raspberry Pi
since it would end up using less power, and would really just be cool.
I installed mono and ran the app and it just worked. I was amazed! However
my app sends emails using gmail when certain events happen, that is the only
part that doesn't work.
I've look through 'the googles' and searched the forum here to try to find
others with the same issue, and I haven't come across any yet. Most people
have issues with the certs, which don't seem to be what I am hitting...yet.
*Here is the exception I get.*
System.Net.Mail.SmtpException: Message could not be sent. --->
System.ArgumentOutOfRangeException: Argument is out of range.
at System.Globalization.DateTimeFormatInfo.GetAbbreviatedDayName
(DayOfWeek dayofweek) [0x00000] in <filename unknown>:0
at System.DateTimeUtils.ToString (DateTime dt, Nullable`1 utc_offset,
System.String format, System.Globalization.DateTimeFormatInfo dfi) [0x00000]
in <filename unknown>:0
at System.DateTimeUtils.ToString (DateTime dt, System.String format,
System.Globalization.DateTimeFormatInfo dfi) [0x00000] in <filename
unknown>:0
at System.DateTime.ToString (System.String format, IFormatProvider
provider) [0x00000] in <filename unknown>:0
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage
message) [0x00000] in <filename unknown>:0
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage
message) [0x00000] in <filename unknown>:0
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
[0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
[0x00000] in <filename unknown>:0
at GraphAP21Results.Program.SendEmail (System.String subject,
System.String body, System.String to) [0x00000] in <filename unknown>:0
*I split out the code that is causing a problem into a stand-alone app. Here
is the code.*
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace EmailTest
{
class Program
{
public static void SendEmail(string subject, string body, string to)
{
try
{
System.Net.Mail.MailMessage mail = new
System.Net.Mail.MailMessage();
System.Net.Mail.SmtpClient smtp = new
System.Net.Mail.SmtpClient("smtp.gmail.com");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslErrors) { return true; };
mail.To.Add(to);
mail.From = new
System.Net.Mail.MailAddress("fromAccount at gmail.com");
mail.Subject = subject;
mail.body = body;
mail.IsBodyHtml = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new
System.Net.NetworkCredential("fromAccount", "password"); ;
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(mail);
}
catch (Exception e)
{
Console.WriteLine("Error Sending email");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("{0}", e);
Console.ResetColor();
}
}
static void Main(string[] args)
{
SendEmail("Subject1", "This is Body", "test at test.com");
}
}
}
Any Ideas?
--
View this message in context: http://mono.1490590.n4.nabble.com/SmtpClient-Send-failing-with-Argument-out-of-range-SmtpException-tp4661351.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list