I am using this code to send emails from my website (Taken from here https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/aspnet-c39624/send-an-e-mail-using-aspnet-a604246.html)
//create the mail message
MailMessage mail = new MailMessage();
//set the FROM address
mail.From = new MailAddress(from);
//set the RECIPIENTS
mail.To.Add(to);
//enter a SUBJECT
mail.Subject = subject;
//Enter the message BODY
mail.Body = body;
//set the mail server (default should be smtp.1and1.com)
SmtpClient smtp = new SmtpClient("smtp.1and1.com");
//Enter your full e-mail address and password
smtp.Credentials = new NetworkCredential("admin#blank.com", "Password");
//send the message
smtp.Send(mail);
The emails being sent are not generating the html. So instead of a link showing up it will have the actual code for a link ect.
What am I doing wrong?
You have to add the following line:
mail.IsBodyHtml = true;
Related
I want to send an email in ASP.net where I want to hide the email address that I send to the customers. I want to show them a different email address in the From box so for e.g. I want to send an email from abc#abc.com, this email is authenticated. When the end user receives the email in their inbox, they will see a different address called test#test.com. They can reply to this email. I have this code so far:
testMessage msg = new MailMessage();
msg.To.Add(new MailAddress(txtemail.Text.Tostring(), "To Name"));
msg.From = new MailAddress("abc#abc.com", "From Name");
msg.Subject = "This is a test";
msg.Body = "Hello, this is a test email";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("userName", "PASS");
client.Port = 121;
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
I don't want the customers to see my abc#abc.com email address. Instead of that, I want them to see Test#test.com. How can I achieve this? They can reply to test#test.com. I don't want them to reply to abc#abc.com. I am not sure which settings should I change to do this?
Any help will be highly appreciated.
I have a few domains set up on the gmail servers through a few different accounts.
I can successfully send mail using the following code from one of the accounts (using the credentials I use to log into the cpanel), but when I try and send mail from one of the user accounts (using that user's credentials), nothing goes out.
Is there a setting I need to set on the gmail side to enable this?
here is the code that works but from only the "parent" account on one of my domains:
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("someaddress#somedomain.com", "somepassword");
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("someuser#someotherdomain.com"));
msg.Subject = "Inquiry from blah blah blah";
msg.IsBodyHtml = true;
msg.Body = "blah blah blah";
msg.From = new MailAddress("someaddress#somedomain.com");
client.Send(msg);
When you are trying to send mail frim gmail servers, you must use gmail credentials not your domain credentials.
for example use someaddress#gmail.com & your gmail password.
MailMessage mail = new MailMessage();
mail.To.Add("recipient#yahoo.com");
mail.From = new MailAddress("sommeemail#gmail.com", "sender name");
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("sommeemail#gmail.com","password");
smtp.EnableSsl = true;
smtp.Send(mail);
In my web project, I am trying to programmatically send the contents of a text file that exists within the project to a default email address. Are there any simple ways of doing this in C#?
Something like:
// Read the file
string body = File.ReadAllText(#"C:\\MyPath\\file.txt");
MailMessage mail = new MailMessage("you#you.com", "them#them.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "file";
// Set the read file as the body of the message
mail.Body = body;
// Send the email
client.Send(mail);
Let say your file is /files/file1.txt
So to read it Use :
var content = System.IO.File.ReadAllText(Server.MapPath("/files/file1.txt"));
And Send It by
MailMessage message = new MailMessage();
message.From = new MailAddress("your email address");
message.To.Add(new MailAddress("the target email address"));
message.Subject = "...";
message.Body = content;
var client = new SmtpClient();
client.Send(message);
Here you have an example:
MailMessage message = new MailMessage();
message.From = new MailAddress("from#from.be");
message.To.Add(new MailAddress("to#to.be"));
message.Subject = "Subject goes here.";
message.Body = File.ReadAllText("Path-to-file");
SmtpClient client = new SmtpClient();
client.Send(message);
You should read the mail outside of construction of the e-mail, but it's here just to show the reading of a file.
Kr,
Sample Code: I need functionality for send to your friend...
NetworkCredential loginInfo = new NetworkCredential("admin#gmail.com", "password");
MailAddress to = new MailAddress("mailto#gmail.com");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.Credentials = loginInfo;
MailAddress from = new MailAddress("from#gmail.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "demo";
message.Body = #"msgBody";
client.Send(message);
Reasion is are you using smtp of Gmail.
it would happend due to security issule like... you are using gmail address and send email as xyz#microsoft.com its may create issue....
thats reasion its not allow by gmail.
it may work with your own domain.
You can try this
message.Headers.Add("From", "From Name <from#gmail.com>");
How to set "from" when sendin email via smtp server with using microsoft c#
if you look this image you will understand what i mean
i use the code below for sending emails
MailMessage mail = new MailMessage();
mail.To.Add(srUserEmail);
string srBody = "bla bla bla";
mail.From = new MailAddress("PokemonCraft.Announcement#pokemoncraft.com");
mail.Subject = "bla bla bla";
mail.Body = srBody;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.Host = "xxx.xx.xx.xx";
smtp.Port = xxx;
smtp.Send(mail);
Pass a second argument to the MailAddress constructor:
mail.From = new MailAddress("Announcement#pokemoncraft.com", "Some Display Name")
Format your email address like this:
mail.From = new MailAddress("PokemonCraft <PokemonCraft.Announcement#pokemoncraft.com>");
The MailAddress object should recognize that the part inside <> tags is an email address, whereas the part preceding that is the name of the person or business sending the email.