471,088 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,088 software developers and data experts.

Error sending mail in .net

when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message
550-5.7.1[122.163.196.231] the ip you’re using to send mail is not authorized"

i have configure smtp server put 127.0.0.1 ip in relay and also put 127.0.0.1 ip in connection.
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Web;
  8. using System.Web.Mail;
  9. using System.Web.SessionState;
  10. using System.Web.UI;
  11. using System.Web.UI.WebControls;
  12. using System.Web.UI.HtmlControls;
  13.  
  14. namespace EMailSample
  15. {
  16.     public partial class SendMail : System.Web.UI.Page
  17.     {
  18.  
  19.         protected void Page_Load(object sender, System.EventArgs e)
  20.         {
  21.             if (!IsPostBack)
  22.             {
  23.             }
  24.             lblMessage.Text = "";
  25.         }
  26.  
  27.         #region Web Form Designer generated code
  28.         override protected void OnInit(EventArgs e)
  29.         {
  30.             //
  31.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  32.             //
  33.             InitializeComponent();
  34.             base.OnInit(e);
  35.         }
  36.  
  37.         /// <summary>
  38.         /// Required method for Designer support - do not modify
  39.         /// the contents of this method with the code editor.
  40.         /// </summary>
  41.         private void InitializeComponent()
  42.         {
  43.  
  44.         }
  45.         #endregion
  46.  
  47.         protected void btnsend_Click(object sender, EventArgs e)
  48.         {
  49.             try
  50.             {
  51.                 /* Create a new blank MailMessage */
  52.                 MailMessage mailMessage = new MailMessage();
  53.  
  54.                 mailMessage.From = txtSender.Text;
  55.                 mailMessage.To = txtReceiver.Text;
  56.                 mailMessage.Cc = txtCc.Text;
  57.                 mailMessage.Bcc = txtBcc.Text;
  58.                 mailMessage.Subject = txtSubject.Text;
  59.                 mailMessage.Body = txtBody.Text;
  60.  
  61.                 /* Set the properties of the MailMessage to the
  62.                    values on the form  */
  63.                 if (rblMailFormat.SelectedItem.Text == "Text")
  64.                     mailMessage.BodyFormat = MailFormat.Text;
  65.                 else
  66.                     mailMessage.BodyFormat = MailFormat.Html;
  67.  
  68.                 /* We use the following variables to keep track of
  69.                    attachments and after we can delete them */
  70.                 string attach1 = null;
  71.                 string attach2 = null;
  72.                 string attach3 = null;
  73.  
  74.                 /*strFileName has a attachment file name for 
  75.                   attachment process. */
  76.                 string strFileName = null;
  77.  
  78.                 /* Bigining of Attachment1 process   & 
  79.                    Check the first open file dialog for a attachment */
  80.                 if (inpAttachment1.PostedFile != null)
  81.                 {
  82.                     /* Get a reference to PostedFile object */
  83.                     HttpPostedFile attFile = inpAttachment1.PostedFile;
  84.                     /* Get size of the file */
  85.                     int attachFileLength = attFile.ContentLength;
  86.                     /* Make sure the size of the file is > 0  */
  87.                     if (attachFileLength > 0)
  88.                     {
  89.                         /* Get the file name */
  90.                         strFileName = Path.GetFileName(inpAttachment1.PostedFile.FileName);
  91.                         /* Save the file on the server */
  92.  
  93.                         string path = Server.MapPath(strFileName);
  94.                         inpAttachment1.PostedFile.SaveAs(path);
  95.                         /* Create the email attachment with the uploaded file */
  96.                         MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
  97.                         /* Attach the newly created email attachment */
  98.                         mailMessage.Attachments.Add(attach);
  99.                         /* Store the attach filename so we can delete it later */
  100.                         attach1 = strFileName;
  101.                     }
  102.                 }
  103.                 /* Attachment-2 Repeat previous step */
  104.                 if (inpAttachment2.PostedFile != null)
  105.                 {
  106.                     HttpPostedFile attFile = inpAttachment2.PostedFile;
  107.                     int attachFileLength = attFile.ContentLength;
  108.                     if (attachFileLength > 0)
  109.                     {
  110.                         strFileName = Path.GetFileName(inpAttachment2.PostedFile.FileName);
  111.                         inpAttachment2.PostedFile.SaveAs(Server.MapPath(strFileName));
  112.                         MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
  113.                         mailMessage.Attachments.Add(attach);
  114.                         attach2 = strFileName;
  115.                     }
  116.                 }
  117.                 /* Attachment-3 Repeat previous steps  */
  118.                 if (inpAttachment3.PostedFile != null)
  119.                 {
  120.                     HttpPostedFile attFile = inpAttachment3.PostedFile;
  121.                     int attachFileLength = attFile.ContentLength;
  122.                     if (attachFileLength > 0)
  123.                     {
  124.                         strFileName = Path.GetFileName(inpAttachment3.PostedFile.FileName);
  125.                         inpAttachment3.PostedFile.SaveAs(Server.MapPath(strFileName));
  126.                         MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
  127.                         mailMessage.Attachments.Add(attach);
  128.                         attach3 = strFileName;
  129.                     }
  130.                 }
  131.  
  132.                 /* Set the SMTP server and send the email with attachment */
  133.  
  134.                 // SmtpMail.SmtpServer = "127.0.0.1";
  135.                 SmtpMail.SmtpServer.Insert(0, "127.0.0.1");
  136.                 //SmtpMail.SmtpServer.Insert(0,"192.168.1.7");
  137.                 SmtpMail.Send(mailMessage);
  138.  
  139.                 /* Delete the attachements if any */
  140.                 if (attach1 != null)
  141.                     File.Delete(Server.MapPath(attach1));
  142.                 if (attach2 != null)
  143.                     File.Delete(Server.MapPath(attach2));
  144.                 if (attach3 != null)
  145.                     File.Delete(Server.MapPath(attach3));
  146.  
  147.                 /* clear the controls */
  148.                 txtSender.Text = "";
  149.                 txtReceiver.Text = "";
  150.                 txtCc.Text = "";
  151.                 txtBcc.Text = "";
  152.                 txtSubject.Text = "";
  153.                 txtBody.Text = "";
  154.  
  155.                 /* Dispaly a confirmation message to the user. */
  156.                 lblMessage.Visible = true;
  157.                 lblMessage.ForeColor = Color.Black;
  158.                 lblMessage.Text = "Message Sent.";
  159.             }
  160.             catch (Exception ex)
  161.             {
  162.                 /* Print a message informing the 
  163.                 user about the exception that was risen */
  164.                 lblMessage.Visible = true;
  165.                 lblMessage.ForeColor = Color.Red;
  166.                 lblMessage.Text = ex.ToString();
  167.             }
  168.         }
  169.     }
  170. }
  171.  
please have a look,please help me
Apr 3 '08 #1
3 2181
Plater
7,872 Expert 4TB
raj200809, I deleted your duplicate post.
Please don't double post your questions it's against the posting guidelines
MODERATOR



Now, I don't see anywhere were you supplied your credentials for your SMTP server, some servers will reject you if you don't supply valid(or any) credentials.
Also, are you sure you have a mail server running on localhost or that other LAN IP?
Apr 3 '08 #2
raj200809, I deleted your duplicate post.
Please don't double post your questions it's against the posting guidelines
MODERATOR



Now, I don't see anywhere were you supplied your credentials for your SMTP server, some servers will reject you if you don't supply valid(or any) credentials.
Also, are you sure you have a mail server running on localhost or that other LAN IP?
Your are right but its also not working in localhost due to symentic antivirus.
but when i change mail setting of symentic antivirus. its give me message .
mail send. but i m not recive mail in to address.

if any one have mail method code to send mail please give me the method. i want call the function on button click event and send a confirmation mail to client.

please help me
Apr 7 '08 #3
Plater
7,872 Expert 4TB
Add your credentials for the SMTP server and see what happens.
Apr 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by murph | last post: by
7 posts views Thread by Rajani | last post: by
3 posts views Thread by dgiagio | last post: by
3 posts views Thread by Ibrahim. | last post: by
2 posts views Thread by =?Utf-8?B?QWRl?= | last post: by
5 posts views Thread by Don Quijote de Nicaragua | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.