Major_Disorder
07-21-2003, 12:08 AM
Hi,
I've written a class that sends an email using the SendEmail method (surprise, surprise). The method call works just fine if I call it directly from an ASPX page using the following:
<%@ Page Language="VB" %>
<%@ Import Namespace="mynamespace" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim o As Utils = New Utils
o.SendEmail("x@x.co.uk","x@x.net","Subject","Body")
lblMessage.text = "Mail Sent"
End Sub
</script>
However, if I try to call the method from another class no email is delivered. I can't debug this as it's on the discount.asp servers.
Any one got any ideas what I'll need to change?
BTW the other class calling the SendEmail method is in the same assembly.
***SEND EMAIL***
public bool SendEmail(string sTo, string sFrom, string sSubject, string sBody)
{
try
{
MailMessage oMsg = new MailMessage();
oMsg.From = sFrom;
oMsg.To = sTo;
oMsg.Subject = sSubject;
oMsg.Body = sBody;
oMsg.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(oMsg);
return true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return false;
}
}
I've written a class that sends an email using the SendEmail method (surprise, surprise). The method call works just fine if I call it directly from an ASPX page using the following:
<%@ Page Language="VB" %>
<%@ Import Namespace="mynamespace" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim o As Utils = New Utils
o.SendEmail("x@x.co.uk","x@x.net","Subject","Body")
lblMessage.text = "Mail Sent"
End Sub
</script>
However, if I try to call the method from another class no email is delivered. I can't debug this as it's on the discount.asp servers.
Any one got any ideas what I'll need to change?
BTW the other class calling the SendEmail method is in the same assembly.
***SEND EMAIL***
public bool SendEmail(string sTo, string sFrom, string sSubject, string sBody)
{
try
{
MailMessage oMsg = new MailMessage();
oMsg.From = sFrom;
oMsg.To = sTo;
oMsg.Subject = sSubject;
oMsg.Body = sBody;
oMsg.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(oMsg);
return true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return false;
}
}