The from and to obviously have to be valid email addresses. The hostname/IP address for the smtp server cant be http://....... ---> change to a realistic name.
Appologies, I was thinking of the mail messages properties (the to and from addresses must be of type MailAddress).
I mean the name "http://......" will obviously not work, im guessing you obmitted it for security reasons!? It can take either a host name or an IP address. This is the code im using (and definatly works!):
Code behind:
MailMessage
mm = new
MailMessage();
try
{
mm.To.Add(new
MailAddress(User@domain.com));
mm.Subject ="Subject";
mm.Body = "body";
mm.IsBodyHtml = true;
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at sendemail.Service1..ctor() in C:\My Documents\Visual Studio 2005\sendemail\sendemail\Service1.cs:line 30
at sendemail.Program.Main() in C:\My Documents\Visual Studio 2005\sendemail\sendemail\Program.cs:line 22
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Samiraek
Member
35 Points
30 Posts
Failure sending mail
Jul 20, 2007 04:37 PM|LINK
i am trying to send mailmessage in a windows service,but it fails,here is the code:
MailMessage msgMail = new MailMessage("from", "to", "subject", "message body"); SmtpClient smtp = new SmtpClient("http:\\......"); smtp.EnableSsl = true;smtp.DeliveryMethod =
SmtpDeliveryMethod.Network; smtp.Credentials = new System.Net.NetworkCredential("username", "password", "domain");smtp.Send(msgMail);
what can be the problem?
thanks
DavidKiff
Star
8660 Points
1733 Posts
Re: Failure sending mail
Jul 20, 2007 05:19 PM|LINK
Where do we start???
MailMessage msgMail = new MailMessage("from", "to", "subject", "message body");
"from" and "to" are not in an overload for MailMessage- it takes type MailAddress:
new
MailAddress(from@domain.com)The from and to obviously have to be valid email addresses. The hostname/IP address for the smtp server cant be http://....... ---> change to a realistic name.
Visit my site
Follow me on Twitter
Samiraek
Member
35 Points
30 Posts
Re: Failure sending mail
Jul 20, 2007 06:35 PM|LINK
from and to can be string and they are valid.
as for hostname ive checke ip address as well same error!
what u mean by realistic name?
thanks
DavidKiff
Star
8660 Points
1733 Posts
Re: Failure sending mail
Jul 20, 2007 10:16 PM|LINK
Appologies, I was thinking of the mail messages properties (the to and from addresses must be of type MailAddress).
I mean the name "http://......" will obviously not work, im guessing you obmitted it for security reasons!? It can take either a host name or an IP address. This is the code im using (and definatly works!):
Code behind:
MailMessage
mm = new MailMessage();try
{
mm.To.Add(new MailAddress(User@domain.com));
mm.Subject ="Subject";
mm.Body = "body";
mm.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient();
try { smtpClient.Send(mm); return true; }
catch (Exception e) { Error.Report(e); }
}
catch (Exception e) { Error.Report(e); }
mm.Dispose();
In my web.config file i have configured the site-wide settings (just before </configuration>):
<system.net><
mailSettings> <smtp from=Admin@mydomain.com><
network host="smtp.mydomain.com" password="password" userName="username" /> </smtp></
mailSettings></
system.net>Visit my site
Follow me on Twitter
Samiraek
Member
35 Points
30 Posts
Re: Failure sending mail
Jul 20, 2007 10:35 PM|LINK
i wrote that its a windows service also ive tried ip address same error!
plus once u r using web page is ok to write with HTTP and it is working in my code
just i cant do the same in windows service.
DavidKiff
Star
8660 Points
1733 Posts
Re: Failure sending mail
Jul 20, 2007 10:42 PM|LINK
Ok, whats the error? do you have the stack trace?
Visit my site
Follow me on Twitter
Samiraek
Member
35 Points
30 Posts
Re: Failure sending mail
Jul 21, 2007 02:00 AM|LINK
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at sendemail.Service1..ctor() in C:\My Documents\Visual Studio 2005\sendemail\sendemail\Service1.cs:line 30
at sendemail.Program.Main() in C:\My Documents\Visual Studio 2005\sendemail\sendemail\Program.cs:line 22
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
DavidKiff
Star
8660 Points
1733 Posts
Re: Failure sending mail
Jul 21, 2007 10:03 AM|LINK
ok and the actual error?
Visit my site
Follow me on Twitter
Samiraek
Member
35 Points
30 Posts
Re: Failure sending mail
Jul 22, 2007 08:50 AM|LINK
{"The remote name could not be resolved: 'x.com.ua'"}
ive tried ip address also same error.
Prashant Kumar
Star
10846 Points
1752 Posts
Re: Failure sending mail
Jul 22, 2007 09:14 AM|LINK
Try the test described at the following link
http://support.microsoft.com/kb/153119
Prashant