[Mono-dev] Problem sending Mail with Mono 1.1.16
Carlos Kassab
ckassab at eplsite.org
Wed Jul 12 14:32:28 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all, i have this method:
public static string SendMail(String FromMail, String ToMail,
String MailSubject, String MailBody, String MailFormat)
{
String OutValue = "";
///////Exception ex = Server.GetLastError();
MailMessage email = null;
SmtpClient MySMTP = null;
MySMTP = new SmtpClient();
email = new MailMessage();
email.From = new MailAddress(FromMail);
email.To.Add(ToMail);
email.Subject = MailSubject;
email.Body = MailBody;
if (MailFormat == "HTML")
{
email.IsBodyHtml = true;
}
else
{
email.IsBodyHtml = false;
}
email.Priority = MailPriority.High;
MySMTP.Host =
ConfigurationManager.AppSettings["SMTPServer"].ToString();
if
(ConfigurationManager.AppSettings["SMTRequireAuthentication"].ToString()
== "1")
{
MySMTP.Credentials = new
System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUser"].ToString(),
ConfigurationManager.AppSettings["SMTPPassword"].ToString());
}
try
{
MySMTP.Send(email);
}
catch (Exception ex)
{
OutValue = "ERROR: " + ex.Message;
}
return OutValue;
}
When i run it with ms .net, it works fine but when i run it with mono
1.1.16 i get the next error:
Unhandled Exception: System.NullReferenceException: Object reference
not set to
an instance of an object
at Monomtpostventaadapter.SendEmail.SendMail (System.String
FromMail, System.S
tring ToMail, System.String MailSubject, System.String MailBody,
System.String M
ailFormat) [0x00000]
at Monomtpostventaadapter.MainClass.Main (System.String[] args)
[0x00000]
i found that the problem is in this line:
email.To.Add(ToMail);
i am calling the method in this way:
MailError = SendEmail.SendMail("from at mydomain.com", "to at mydomain.com",
"Error updating", Errors, "TEXT");
What do you think could be the problem?
Thank you in advance for your help.
Carlos Kassab
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEtUA8tsR4STLctmIRAlRaAJ90BfAxu4NfbAknq+XZSsFZbhgSNwCdGb0+
dyHOIbn+0VgLh56FhoVSmVU=
=XYWE
-----END PGP SIGNATURE-----
More information about the Mono-devel-list
mailing list