how to send mail from local

Posted by Abhi_patil under ASP.NET on 4/17/2009 | Views : 8369 | Status : [Member] | Replies : 3
i am trying to send email from local m/c but it is giving error that
" Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server. "

this is my code
//
MailMessage mail = new MailMessage();

mail.To.Add("abhi_560@yahoo.com");

mail.From = new MailAddress("smswonders@smswonders.com");

mail.Subject = "Test Email";

string Body = "Welcome to SMSWonders.Com!!";

mail.Body = Body;

SmtpClient smtp = new SmtpClient();

//smtp.Host = "localhost";
//smtp.Port = 25;

smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "mail.smswonders.com";
//smtp.Host = "localhost";


smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("smswonders@smswonders.com", "sms456");

smtp.Send(mail);
//




Responses

Posted by: Vuyiswamb on: 4/17/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Afternoon Abhi_patil

try it in this Format and see


Dim Smtp As New SmtpClient()

Dim SmtpUser As New System.Net.NetworkCredential("abc@cool.com", "xxxxx")

'setting smtpuser to smtpclient

Smtp.Host = "smtp.cool.com"

Smtp.DeliveryMethod = SmtpDeliveryMethod.Network

Smtp.UseDefaultCredentials = False

Smtp.Credentials = SmtpUser

'Smtp.Port = 25

Smtp.Send(mail)


In addiotion this might help

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx


Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi_patil on: 4/17/2009 [Member] Starter

Up
0
Down
i am doing in c#.

i tried it in but it is giving error - Failure sending mail.
and Unable to connect remote server

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 8/31/2009 [Member] [Moderator] Silver

Up
0
Down
User needs to pass few parameter to this method to send the mail.
body - Content of email that you want to send.
toadd - Address of the user to whom you want to send the Email.
ccAdd - Address of the user to whom you want to send Email in CC.
bccadd -Address of the user to whom you want to send Email in BCC.
fromaddm - Address of the user that want to send the Email.
subject - Subject of the Email.
attachment - Attachment any if you want to send to user otherwise set the value as blank if you don't want to send any email.

Address of SMTP Server - Replace this text with the address of your SMTP Server.
Code To Send Email:
public static bool SendMail(string body, string toadd, string fromadd, string subject, string attachment, string ccAdd, string bccadd)
{
string mailServerName = "Address of SMTP Server ";
try
{
//MailMessage represents the e-mail being sent
using (MailMessage message = new MailMessage(fromadd, toadd, subject, body))
{
if (attachment != "")
{
message.Attachments.Add(new Attachment(attachment));
}
if (bccadd != "")
{
message.Bcc.Add(bccadd);
}
message.IsBodyHtml = true;
message.Priority = MailPriority.Normal;
SmtpClient mailClient = new SmtpClient();
mailClient.Host = mailServerName;
mailClient.UseDefaultCredentials = true;
mailClient.Send(message);

}
return true;
}
catch (SmtpException ex)
{

return false;
}
catch (Exception ex)
{

return false;
}
}

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response