techques
asked on
How to configure the parameters in System.Net.Mail and send email?
Hi
I use System.Net.Mail to send email. But, it has error. The smtp ac does work when I use in outlook.
How should I set the parameters:
msg.ReplyTo = to;
msg.DeliveryNotificationOp tions = DeliveryNotificationOption s.OnFailur e.ToString ();
as it said the errors are not able to convert string to msg.ReplyTo and DeliveryNotificationOption s.
I use System.Net.Mail to send email. But, it has error. The smtp ac does work when I use in outlook.
How should I set the parameters:
msg.ReplyTo = to;
msg.DeliveryNotificationOp
as it said the errors are not able to convert string to msg.ReplyTo and DeliveryNotificationOption
public void SendMailNow(string from, string to, string title, string content)
{
SmtpClient smtp = new SmtpClient(Host);
if (IsUserCredentials)
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = Credential;
}
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage msg = new MailMessage(from, to, title, content);
msg.IsBodyHtml = true;
msg.ReplyTo = to;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure.ToString();
msg.BodyEncoding = Encoding.GetEncoding(950); //936 - simplified chinese
msg.SubjectEncoding = Encoding.GetEncoding(950); //950 - traditional chinese
smtp.Send(msg);
}
this line:
msg.ReplyTo = to;
should read:
msg.ReplyTo = new MailAddress(to);
And REA_ANDREW already replied for the DeliveryNotificationOption s
msg.ReplyTo = to;
should read:
msg.ReplyTo = new MailAddress(to);
And REA_ANDREW already replied for the DeliveryNotificationOption
oops missed that one. :-)
ASKER
Hi
I edited the code and try again. It has an exception: -
$exception {"Failure sending mail."} System.Exception {System.Net.Mail.SmtpExcep tion}
I use VC# to develop that windows service program.
What's wrong with it?
I edited the code and try again. It has an exception: -
$exception {"Failure sending mail."} System.Exception {System.Net.Mail.SmtpExcep
I use VC# to develop that windows service program.
What's wrong with it?
using System.Net.Mail;
public void SendMailNow(string from, string to, string title, string content)
{
SmtpClient smtp = new SmtpClient(Host);
if (IsUserCredentials)
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = Credential;
}
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage msg = new MailMessage(from, to, title, content);
msg.IsBodyHtml = true;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
msg.BodyEncoding = Encoding.GetEncoding(950); //936 - simplified chinese
msg.SubjectEncoding = Encoding.GetEncoding(950); //950 - traditional chinese
smtp.Send(msg);
}
public const string SmtpClientHostFrom = "a@test.com";
public const string SmtpClientHost = "smtp.test.com";
public const string SmtpClientIsUserCredentials = "true";
public const string SmtpClientIsOnlyForLocUser = "false";
public const string SmtpClientCredentialAccount = "admin@test.com";
public const string SmtpClientCredentialPassword = "1234";
is your smtp server is really at "smtp.test.com" ?
ASKER
no, it is an example.
i use smtp server in outlook with username and password
i use smtp server in outlook with username and password
it is really hard to figure it out without the exact exception. have a look at http://www.systemnetmail.com/
ASKER
Hi
I read http://www.systemnetmail.com/allfaq.aspx and edited the code, it has the same error: Failure to send email.
How can I fix it now?
I read http://www.systemnetmail.com/allfaq.aspx and edited the code, it has the same error: Failure to send email.
How can I fix it now?
public void SendMail(string to, string title, string content)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("me@mycompany.com","My Company Name");
msg.To.Add(to);
msg.Subject = title;
msg.Body = content;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.ReplyTo = new MailAddress("me@mycompany.com");
msg.Headers.Add("Disposition-Notification-To", "me@mycompany.com");
msg.SubjectEncoding = Encoding.GetEncoding(950);
msg.BodyEncoding = Encoding.GetEncoding(950);
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient smtp = new SmtpClient(smtp.sample.com);
smtp.Credentials = new NetworkCredential("testusr", "testpwd");
smtp.Send(msg);
}
have a look at "5 Troubleshooting System.Net.Mail" to trace all inner exceptions
ASKER
If I use home network to send email, it does not work.
However, if I use my friend's network, it can send email.
Why is that case?
However, if I use my friend's network, it can send email.
Why is that case?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>If I use home network to send email, it does not work.
Your SMTP server is not set/installed correctly
Your SMTP server is not set/installed correctly
replace
msg.DeliveryNotificationOp
with
msg.DeliveryNotificationOp