Skip to content

The problem with sending mail

benzema kirism

Asked Sep 16, 2010, 7:24 PM EDT7 answers
Share
LinkedInX
Hi all.
i am uisng visual studio 2003 to create simple web for sending mail base on the smtp server like that :
 
Java
 

string smtpServer = "smtp.gmail.com";

string userName = "metilmarket";

string password = "i5kngyvx";

int cdoBasic = 1; 

int cdoSendUsingPort = 2; 

MailMessage msg = new MailMessage(); 

if (userName.Length > 0) 

{

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer); 

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort); 

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName); 

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); 

} 

msg.To = "[email protected]";

msg.From = "[email protected]";

msg.Subject = "Subject";

msg.Body = "Message";

SmtpMail.SmtpServer = smtpServer;

SmtpMail.Send(msg);

lb1mgs.Text = "Your message has been successfully sent.";

But i am get error when i do the transaction with smtp :
errors like that :
The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command  first. n35sm3933492wfa.15
 i am using gmail to test this application.
 Please give me suggestion , how to correct it ?
 
thanks in advances.
 
 

7 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Mail;

    namespace consolemail
    {
        class Program
        {
            static void Main(string[] args)
            {
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                System.Net.NetworkCredential AuthInfo = new
                System.Net.NetworkCredential("[email protected]", "babilona");

                message.To.Add("[email protected]");

                message.Subject = "Test Mail using System.Net.Mail";
                message.From = new MailAddress("[email protected]");
                string str = "Hai to all";
                message.Body = str;
                bool isBodyHtml = true;
                message.IsBodyHtml = isBodyHtml;
                message.Attachments.Add(new Attachment("c:\\something.txt"));
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.BodyEncoding = System.Text.Encoding.UTF8;


                message.Priority = MailPriority.High;



                smtp.Host = "smtp.gmail.com";
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = AuthInfo;
                smtp.Timeout = 20000;
                smtp.Port = 587;
                // use stmp.port = 587 if 465 does not work.
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                try
                {
                    smtp.Send(message);
                    Console.WriteLine("E-mail has been sent succesfully");
                    Console.ReadLine();
                    
                }

                catch (System.Net.Mail.SmtpException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }
        }
    }


    Hai use this peice of code..Hope it helps u...


    If My Answer Helped u don't forget to mark it .....


    0
  • 0
    Dear krishna prasad.
    many thanks to you.
    To base your code , i am get the error like that :
    The SMTP server requires a secure connection or the client was not authenticated. the server response was: 5.5.1 Authentication required
    and i also change port that it is
    smtp.Port = 465;
    still get error : request time out :
     
    thanks and best regards.
     
    0
  • 0
    Hai...

    Please check your network credentials...the user name and password (i.e "metilmarket"; "i5kngyvx"; ) is incorrect..Try a give a valid gmail id and password...which u use...

    System.Net.NetworkCredential("[email protected]", "babilona");    and replace here....

    And also...have a text file called something.txt in c: ........cause i have added it in my code...

     message.Attachments.Add(new Attachment("c:\\something.txt"));  as an attachment...

    Later u can modify as per ur requirements...


    Hope i made myself clear....Feel free to ask any doubts...
    0
  • 0
    Dear.
    are there another solution to send mail if i am don't use the library( System.Net.Mail;) and replace to (System.Web)?
    because my server is using visual studio 2003 that it is has trouble according to sending mail.
    thanks
    0
  • 0
    Hai...

    Please check your network credentials...the user name and password (i.e "metilmarket"; "i5kngyvx"; ) is incorrect..Try a give a valid gmail id and password...which u use...

    System.Net.NetworkCredential("[email protected]", "babilona");    and replace here....

    And also...have a text file called something.txt in c: ........cause i have added it in my code...

     message.Attachments.Add(new Attachment("c:\\something.txt"));  as an attachment...

    Later u can modify as per ur requirements...


    Hope i made myself clear....Feel free to ask any doubts...
    0
  • 0
    Thanks you .
    it is run well now (the error on incorrect password), i am test it run on framwork 3.5  , but when i am test it on framework 1.1  , it is not include the library System.Net.Mail.
    it just have system.Web.mail.
     
    thanks
     
    0
  • 0
    Hai...

    yes u have to have the latest framework......


    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    If my answer helped you........Don't forget to mark it as correct answer....
    0