I am using MailMessage for sending mail. I have remote smtp server for which I want to add fields like username, password, port etc. There is way by addming field in it by using .net1.1 . But what if I am using .net1.0 .
What is the way to send the mail using 1.0??
What is the way to send the mail using 1.0??
nagabhushan hegdePosted Mar 8, 2006, 11:28 AM
Hi,
The below code may be useful for you. Make sure that your smtp name is proper.
//Function to send a mail.
public int sendMail(string to,string cc,string bcc,string subject,string body)
{
try
{
SmtpMail.SmtpServer="your_server_address";
MailMessage msg = new MailMessage();
msg.From = "your_email_id";
msg.To = to;
msg.Cc = cc;
msg.Bcc = bcc;
msg.Subject = subject;
msg.Body = body;
SmtpMail.Send(msg);
return(1);
}
catch
{
return (0);
}
}
//Button Click event - code for sendign message.
private void Button1_ServerClick(object sender, System.EventArgs e)
{
String to = “to_email_id”;
String cc = “cc_email_id”;
String bcc = “bcc_email_id”;
String subject = “your subject goes here”;
String body = “your body text goes here”;
int status = sendMail(to,cc,bcc,subject,body);
if(status == 1)
Response.Write("your mail has been sent successfully");
else
Response.Write("sorry! your mail could not be sent”);
}