Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I get a problem about sending email,
I will get a feedback from myemail address,If send email failure
Here is the code:

protected void SendEmail(string strFrom, string strTo, string strCc, string strSubject, string strMessage, string lang)
{
    try
    {
        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
        strFrom = strFrom.Trim();
        strTo = strTo.Trim();
        strCc = strCc.Trim();
        if (lang == "Japanese")
        {
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
        }
        else
        {
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
        }
        msg.From = new System.Net.Mail.MailAddress(strFrom);
        msg.To.Add(strTo);
        if (strCc != "")
        {
            string[] cctoS = strCc.Split('^');
            for (int i = 0; i < cctoS.Length; i++)
            {
                msg.CC.Add(cctoS[i]);
            }
        }
        msg.Subject = strSubject;
        msg.IsBodyHtml = true;
        msg.Body = strMessage;
        msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
        msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");

        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

        //For get message,if send email fail.
        msg.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions. .OnFailure;

        msg.ReplyTo = new System.Net.Mail.MailAddress("myemailaddress");

        smtp.Host = "smtp-au.server-mail.com";
        smtp.Send(msg); //send email out

    }
    catch (Exception err)
    {

    }


}
Posted
Updated 23-Sep-10 19:05pm
v3

1 solution

try giving port no smtp.port=587;
 
Share this answer
 
Comments
laoyingisme 24-Sep-10 3:13am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900