Sending outlook mails with adding followup remainders in asp.net c# - c#

while sending mail Adding remainders possible in outlook through asp.net c#
CODE:-
MailMessage msg = new MailMessage();
msg.To.Add("emailid");
msg.From = new MailAddress("fromid");
msg.IsBodyHtml = true;
msg.Body = "";
msg.Subject = "Alert!";
SmtpClient smtp = new SmtpClient();
smtp.Host = "host id";
msg.Priority = MailPriority.High;
msg.Headers.Add("X-Message-Flag", "For Your Information");
msg.Headers.Add("Reply-By", "08/06/2015 13:05:00"); smtp.Send(msg);

I think you mean reminder not remainder.
Please see below for what you would need to add to your code
DateTime replyDate = DateTime.Now.AddHours(4);
MailMessage msg = new MailMessage();
msg.Headers.Add("X-Message-Flag", "Follow up");
msg.Headers.Add("Reply-By", String.Format("{dd/MM/yyyy HH:mm:ss}", replyDate));

Related

Why do I get an error by trying to send a mail with c#?

I'm trying to send an e-mail using C#, but I get this recurring error :
.
Can you explain me what's wrong with my code ?
Here it is :
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("myEmailAdress#gmail.com", "myPassword");
MailMessage msg = new MailMessage();
msg.To.Add("receiver#gmail.com");
msg.From = new MailAddress("sender#gmail.com");
msg.Subject = "My subject";
msg.Body = "My body";
client.Send(msg);
MessageBox.Show("Message sent !");
I have encountered same before.
You are getting this error because you haven't set ON on Less secure app access for sender#gmail.com as you are using Gmail SMTP port.
Reason:
Your email has no remotely access permission. You have to configure
it. Suppose you want to sent email from sender#gmail.com so you
have set that permission NO to this account.
How To Set:
You could try like below
Or can open that tab from this link directly Less secure app access
Update:
As per your comment this is for you which has working perfectly since the beginning of my career
public object SendMail(string fromEmail, string toEmail, string mailSubject, string mailBody, string senderName, string senderPass, string attacmmentLocationPath)
{
try
{
MailMessage mail = new MailMessage();
//Must be change before using
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(fromEmail);
mail.To.Add(toEmail);
mail.Subject = mailSubject;
mail.Body = mailBody;
mail.IsBodyHtml = true;
// mail.Attachments.Add(new Attachment(#attacmmentLocationPath));
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderName, senderPass);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
return true;
}
catch (Exception ex)
{
return ex;
}
}
Hope that would help.
This code works for gmail, it is very similar to yours with slight differences, but if you try this, and it doesn't work for you, the issue is not the code - perhaps some other network related issue that you are going to need to fix first:
using (var msg = new MailMessage())
{
msg.From = new MailAddress("fromaddress#gmail.com");
msg.To.Add("toaddress#gmail.com");
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("xxx#gmail.com","password");
smtp.Send(msg);
}
}
An SMTP client may log in using an authentication mechanism chosen among those supported by the SMTP servers.

I am not able to send emails from C# code from godaddy VPS hosting

I am not able to send emails from my C# code via Godaddy VPS hosting.
I am getting the following error:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'relay-hosting.secureserver.net' at System.Net.ServicePoint.GetConnection
My C# code is:
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(toEmailId));
msg.From = new MailAddress(fromEmailId);
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Port = 25;
client.Host = "relay-hosting.secureserver.net";
Please help.
try adding this to your code
client.EnableSsl = false;
client.UseDefaultCredentials = false;
I found a solution and its working now.
If you are using Godaddy Windows VPS and want to send email notifications from your website below code needs to be used:
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(toEmailId));
msg.From = new MailAddress("email#domain.com");
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("email#domain.com", "password");
client.Port = 25;
client.Host = "localhost";
Also, you need to create the same email on your windows VPS.

.Net email integration won't send using godaddy SMTP Credential

Hi its been almost a day that I've been figuring things out with regards to sending email from godaddy email account to a gmail account. I have had my research online and almost tried everything but no luck .. here's what I made so far.
protected void generateEmail(){
MailMessage mail = new MailMessage ();
mail.From = new System.Net.Mail.MailAddress ("contact#company.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient ();
smtp.Port = 465; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential ("contact#company.com", "password123!"); // [4] Added this. Note, first parameter is Email Address of the sender and the next parameter is the password.
smtp.Host = "relay-hosting.secureserver.net";
//recipient address
mail.To.Add (new MailAddress ("test#gmail.com"));
mail.To.Add (new MailAddress ("testagain#gmail.com"));
//Formatted mail body
mail.IsBodyHtml = true;
string st = "This is a Test Message";
mail.Body = st;
smtp.Send (mail);
}
Can anyone help me out ? would appreciate any hands..
protected void generateEmail()
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("whereEmailWillBeSent#gmail.com");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("mail#company.com");
msg.From = address;
msg.Subject ="Hi this is mail from company";
msg.Body = "Your Message";
SmtpClient client = new SmtpClient();
//for Godaddy
client.Host = "relay-hosting.secureserver.net";
client.Port = 25;
client.EnableSsl = false;
client.UseDefaultCredentials = false;
//Send the msg
client.Send(msg);
//Display some feedback to the user to let them know it was sent
}
}

Using MailMessage to send emails in C#

I am experiencing some problems sending emails with MailMessage. I have two email accounts, (account1#gmail.com, and account2#gmail.com) and I would like account2 to send an email to account one at a button click event.
This is what I have but it's not working. I'm getting and exception saying it's forbidden.
try
{
//do submit
MailMessage emailMessage = new MailMessage();
emailMessage.From = new MailAddress("account2#gmail.com", "Account2");
emailMessage.To.Add(new MailAddress("account1#gmail.com", "Account1"));
emailMessage.Subject = "SUBJECT";
emailMessage.Body = "BODY";
emailMessage.Priority = MailPriority.Normal;
SmtpClient MailClient = new SmtpClient("smtp.gmail.com");
MailClient.Credentials = new System.Net.NetworkCredential("account2#gmail.com", "password");
MailClient.Send(emailMessage);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I have a feeling it's a problem with the Smtp but I have no clue.
Try this:
using (MailMessage emailMessage = new MailMessage())
{
emailMessage.From = new MailAddress("account2#gmail.com", "Account2");
emailMessage.To.Add(new MailAddress("account1#gmail.com", "Account1"));
emailMessage.Subject = "SUBJECT";
emailMessage.Body = "BODY";
emailMessage.Priority = MailPriority.Normal;
using (SmtpClient MailClient = new SmtpClient("smtp.gmail.com", 587))
{
MailClient.EnableSsl = true;
MailClient.Credentials = new System.Net.NetworkCredential("account2#gmail.com", "password");
MailClient.Send(emailMessage);
}
}
I added the port to the smtp client and enabled SSL.
If port 587 doesn't work, try port 465.
Try:
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(txtUsername.Text);
Msg.To.Add(txtTo.Text);
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
You have not define port number. it should be 587. and use enableSsl=true
as below:
SmtpClient MailClient = new SmtpClient("smtp.gmail.com",587);
Try adding a Port number 587 and enabling SSL on as Gmail uses “strict” SSL security. This means that we’ll always enforce that your other provider’s remote server has a valid SSL certificate.:
try
{
//do submit
MailMessage emailMessage = new MailMessage();
emailMessage.From = new MailAddress("account2#gmail.com", "Account2");
emailMessage.To.Add(new MailAddress("account1#gmail.com", "Account1"));
emailMessage.Subject = "SUBJECT";
emailMessage.Body = "BODY";
emailMessage.Priority = MailPriority.Normal;
SmtpClient MailClient = new SmtpClient("smtp.gmail.com", 587);
MailClient.Credentials = new System.Net.NetworkCredential("account2#gmail.com", "password");
MailClient.EnableSsl = true;
MailClient.Send(emailMessage);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MailMessage objMail = new MailMessage();
SmtpClient objSMTP = new SmtpClient("from.google.uk");
MailAddress objTo = new MailAddress("e-mail", "name");
string sql = "Select Naam, Mail from tblMail";
OleDbCommand cmdMail = new OleDbCommand(sql, cnnConnectie);
OleDbDataReader dtrMail = default(OleDbDataReader);
cnnConnectie.Open();
dtrMail = cmdMail.ExecuteReader();
while (dtrMail.Read())
{
objMail.To.Add(dtrMail["Mail"].ToString());
objMail.From = objTo;
objMail.Body = "test";
objMail.Subject = dtrMail["name"].ToString();
objSMTP.Send(objMail);
}
cnnConnectie.Close();

Set "From" address when using System.Net.Mail.MailMessage?

I'm trying to send a password reset email, but I'm having trouble figuring out how to specify the sender's address.
Here's what I'm trying to do:
MailMessage mail = new MailMessage();
mail.From.Address = "support#mycompany.com";
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "Click here to reset your password.";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);
I'm sure it's possible, so how can I accomplish this in ASP.Net?
It turns out I was getting ahead of myself.
Removing Address from mail.From.Address allowed me to set the value, but needed the type MailAddress.
Here's the solution:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("support#mycompany.com");
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "Click here to reset your password.";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);

Categories