Send Email to GoDaddy using asp.net - asp.net

I am using below code to send email to webmail GoDaddy and it is working fine from my local machine and when deployed on client server it is not working.
Below is my code :
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
MailAddress fromAddress = new MailAddress("xyz#com");
message.From = fromAddress;
message.To.Add("abc#gmail.com");
message.Subject = "test Message";
message.IsBodyHtml = true;
message.Body = "we are here";
smtpClient.Host = "mail.trustwellhospitals.com";
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false;
System.Net.NetworkCredential("username", "password");
smtpClient.Send(message);

Related

Sending mail in asp.net using Exchange Server(smtp-outlook.office365.com)

We are working in Mailing system in asp.net,our client using Microsoft exchange server outlook.office365. We are getting this exception.
"System.Net.Mail.SmtpException: The operation has timed out " error .Please help us.
btn_click(){
try{SmtpClient smtp = new SmtpClient("smtp.outlook.office365.com");
smtp.Host = "outlook.office365.com";
smtp.Port = System.Convert.ToInt32("443");
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("userid", "mypwd");
smtp.Credentials = cred;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.TargetName = "STARTTLS/outlook.office365.com";
MailMessage msg = new MailMessage();
msg.From = new MailAddress("frommailid", "username");
msg.To.Add(new MailAddress("xxx#xxx.com"));
msg.Subject = "Test";
msg.Body = "Test mail ";
smtp.Timeout = 60000;
smtp.Send(msg);
}catch(exception ex)
{
throw ex;
}
}
Refer the below code snippet and try this out. It worked for me.
Remember: From field should be same email id which is used as an SMTP user. So in this example, xxx#blabla.onmicrosoft.com should be the From email id.
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress(ToField.Text));
mail.From = new MailAddress(FromField.Text); //From field should be same email id which is used as a SMTP user.
mail.Subject = "Email Subject";
mail.Body = "Message Body";
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("xxx#blabla.onmicrosoft.com", "Password");
client.Port = 587;//You can use Port 25 if 587 is blocked
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.TargetName = "STARTTLS/smtp.office365.com";
try {
client.Send(mail);
}
catch (Exception ex) {
ResponseLabel.Text = "Error:" + ex.Message;
}

Sending Email from gmail from localhost through Asp.net

Sometimes following code sends Email,Sometimes i get SMTP Exception saying "failure in sending Email".Why is this happening? following is the code i have written.Plesae tell me why sometime i get email sent and sometime why i get Exception.
StringBuilder mailBody = new StringBuilder();
mailBody.Append("Hi <br/>")
MailMessage message = new MailMessage("from#gmail.com", "to#gmail.com");
message.Subject = "Subject";
message.Body = mailBody.ToString();
SmtpClient smtpclient = new SmtpClient("smtp.gmail.com", 587);
smtpclient.Credentials = new System.Net.NetworkCredential()
{ UserName = "from#gmail.com",
Password = "password"
};
smtpclient.EnableSsl = true;
message.IsBodyHtml = true;
smtpclient.Send(message);

Sending Email through Smtp

i'm unable to send mail, exception "Failure sending mail"
what should i do to correct the code?
MailMessage mailMessage = new MailMessage("yourmail#mail.com", ToEmail);
StringBuilder sbEmailBody = new StringBuilder();
sbEmailBody.Append("<b>Registration Approval for</b></br>");
sbEmailBody.Append(InstituteName + "<br/><br/>");
sbEmailBody.Append("Thanks for your registration ");
sbEmailBody.Append("<br/>");
mailMessage.IsBodyHtml = true;
mailMessage.Body = sbEmailBody.ToString();
mailMessage.Subject = "Confirmation Mail!";
SmtpClient smtpClient = new SmtpClient("smtp.mail.com", 587);
smtpClient.Credentials = new System.Net.NetworkCredential()
{
UserName = "yourmailn#mail.com",
Password = " "
};
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);

how to attach a file in email using shared hosting server?

I want to attach a file dynamically and send it through mail. So can someone please let me know how can i send it with attachment.
You can use this code.
using System.Net.Mail;
private void SendEmail()
{
MailMessage message = new MailMessage();
message.From = new MailAddress("YourEmailAddress#domain.com");
message.To.Add(new MailAddress("Recipient#domain.com"));
message.Subject = "Subject";
message.Body = "Email Message Body";
// Add attachment
string attachmentPath = Server.MapPath("~/AttachmentPath.jpg");
message.Attachments.Add(new Attachment(attachmentPath));
// Connect to GoDaddy SMTP
SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net");
smtp.Credentials = new System.Net.NetworkCredential("Username","Password");
smtp.Port = 25;
smtp.EnableSsl = false;
// Send the message
smtp.Send(message);
}
you can try with this code
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("...");/:Adjust your adress
mail.From = new MailAddress("your_email_address#gmail.com");
mail.To.Add("to_address");
mail.Subject = "Test Mail";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("your attachment file");
mail.Attachments.Add(attachment);
SmtpServer.Port = ..; //Replace with your port number
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

how to send mail in asp.net

hii
i m trying to send mail through coding of asp
is there any external APIs to send mail like JAVA
give some hints
if possible sample code!!
I m using vs 2005 as well as vs 2008
You could use the SmtpClient class. Example using GMail's SMTP:
var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("youraccount#gmail.com", "secret");
var mail = new MailMessage();
mail.From = new MailAddress("youraccount#gmail.com");
mail.To.Add("youraccount#gmail.com");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);
UPDATE:
Example with yahoo:
var client = new SmtpClient("smtp.mail.yahoo.com", 587);
client.Credentials = new NetworkCredential("youraccount#yahoo.com", "secret");
var mail = new MailMessage();
mail.From = new MailAddress("youraccount#yahoo.com");
mail.To.Add("destaccount#gmail.com");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);
Try this:
using System.Web.Mail;
private void SendMessage()
{
MailMessage mail = new MailMessage();
mail.To = txtTo.Text;
mail.From = txtFrom.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
}
if want to send attachment
Add the following code
mail.Attachments.Add(new MailAttachment(#"C:\myFile.txt"));

Resources