How to sending email in C# without entering password? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
How do you send an email without entering a password?
I made this:
client.Port = 587;
client.Host = "smtp.gmail.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(emailtxt.Text.Trim());
mail.To.Add("myadressemail#gmail.com");
mail.Subject = "test";
mail.Body = "test";
mail.IsBodyHtml = true;
client.Send(mail);
Is it possible to send an email to Gmail without an authorization?
If not, are there any better alternatives?
Less secure apps are off.

Is it possible to send an email to Gmail without an authorization?
No
If not, are there any better alternatives?
As Mason mentions in the comments, the main alternatives are:
Use a mailto-link to open the users default email program to send the message. This will obviously reveal the email address, but presumably this would happen anyway if you reply to their email.
Setup a simple web-api that receives messages from your application and forwards them to an internal smtp server, or some other system to handle messages. If you want to reply to the user using email you would need to ask him/her for their email address. If you want to ensure the email is correct you could send an automated verification email to the address, and only forward the message once the address has been verified.
There is no real way getting around the need for authentication on the modern internet. The modern way of dealing with this in automated systems would typically be with certificates and API-keys, but email is a quite old protocol with more limited authentication methods.

Related

Send email in asp.net mvc without using credentials like in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Is it possible to send an email in ASP.NET MVC without using credentials like in PHP.
In PHP I simply use the mail method to send an email without using any credentials. How can I do the same thing in C#?
It'll use default credentials.
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(EMAIL_FROM_WHICH_YOU_WANT_TO_SEND_EMAIL);
mail.To.Add(new MailAddress(EMAIL_TO_WHOM_YOU_WANT_TO_SEND_EMAIL));
mail.Subject = YOUR_SUBJECT;
mail.Body = BODY_OF_EMAIL;
mail.IsBodyHtml = true/false[BASED_ON_YOUR_BODY];
smtpClient.Send(mail);
and you'll need to add this in web.config file.
<system.net>
<mailSettings>
<smtp from="[URL]" deliveryMethod="network">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>

C# Fetch certain email with subject [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How can I fetch an email, that has the subject I'm looking for in Hotmail using C#.
e.g. I want the emails(body/message) that has the word "Yahoo" in its subject.
Tried using many examples online but they weren't really clear. Thanks
You can connect to your hotmail account using the OpenPop.Net open source library. It has a lot of useful methods to communicate with a POP3 server. There is a lot of useful examples online. A simple code to connect to the POP3 server could work look this:
using(Pop3Client client = new Pop3Client())
{
client.Connect(hotmailHostName, pop3Port, useSsl);
client.Authenticate(username, password, AuthenticationMethod.UsernameAndPassword);
// And here you can use the client.GetMessage() method to get a desired message.
// You can iterate all the messages and check properties on each of them.
}
The hotmailHostName should be "pop3.live.com".
The pop3Port should be 995.
The useSsl should be true.

Ways to send e-mail to registered users after 5 minutes in ASP.Net? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In my ASP.net website i have done with sending email to users when they register their self but what i want that when a user register from my website it will automatically send email after 5 minutes instead of immediate sending after registration.
Here is my simple code :
private void SendEmail()
{
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMsg = new MailMessage();
MailAddress fromAddress = new MailAddress("test#test.com");
smtpClient.Host = "mail.test.com";
smtpClient.Credentials = new NetworkCredential("test#test.com", "test");
smtpClient.Port = 25;
mailMsg.From = fromAddress;
mailMsg.To.Add(emailid);
mailMsg.Subject = "You are successfully registered";
mailMsg.Body = myString.ToString();
mailMsg.IsBodyHtml = true;
smtpClient.Send(mailMsg);
System.Threading.Thread.Sleep(500000);
}
I used System.Threading.Thread.Sleep(50000) to wait for 5 minutes but this did not help me out to get my exact needs.
I am thinking that i need to set a flag in database table against every registered user email and i will make a webservice which will execute after 5 minutes to see which email addresses needs to be send an email .
Is there any other little fast way to do this?
Store a registration email, and registration date in database (or in text file).
Make a simple different applicication which do the following:
-Checks the current date to the registration date plus 5 minutes.
-if its bigger, send out the email
-if the sending was success, remove the entry from the db
Build this application, and call the exe in every 4-5 minutes via cronjob or windows scheduler

send an email to a recipient entered in a textbox [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a C# Windows forms application with an address book. On the one form there is a text box which displays the contacts email address (from a data table). I'd like to have a button next to it, when clicked it will open up my email client, with the email address entered in.
I understand you can use System.Diagnostics.Process.Start(mailto:example#example.com) to send an email to the specified contact. But how can I get it to send it to the value entered in the text box
Sending emails by pushing it to a default mail client Process.Start('mailto:xxx') is not a good idea. There could be no default email client defined or the default application could just not be configured.
Either way, users will get messages coming not from your application but from the external application.
A better idea is to have an explicit email client configuration for your application and even yet better - allow users to configure email client.
By email client I mean:
SMTP server
port (default: 25)
username
password
With these, your application can easily send emails through the relay SMTP server:
http://msdn.microsoft.com/pl-pl/library/swas0fwc%28v=vs.110%29.aspx
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = body;
SmtpClient client = new SmtpClient(server);
client.Credentials = new NetworkCredentials( username, password );
client.Send(message);

How to preview an HTML email before sending it. C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have developed a program which is sending HTML email using mail definition class.
Is it possible to preview the email before sending it.
Here is a piece of code using mailDefinition :
MailDefinition mailDefinition = new MailDefinition();
mailDefinition.BodyFileName = "C:/Html_Email.htm";
mailDefinition.From = "kami#gmail.com";
ListDictionary ldReplacements = new ListDictionary();
ldReplacements.Add("<%NearTeaser%>", "<b> Welcome to <b>" + nearteaser + "<b>");
ldReplacements.Add("<%Content%>", fulltext);
ldReplacements.Add("<%Weitere%>", "We have these offers for you: " + Weitere);
MailMessage mailMessage = mailDefinition.CreateMailMessage(mailTo, ldReplacements, new System.Web.UI.Control());
mailMessage.IsBodyHtml = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "hostname";
client.Send(mailMessage);
Every thing is working fine. I am curious if it is possible to preview the email before sending it.
Many thanks.
Before sending email display the contents of ldRelacements in a multitext box or in a panel/div.
MailDefinition class allows to create email messages from text files or strings.
Please go through http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.maildefinition(v=vs.110).aspx. It will give you some insights about MailDefinition class and examples.

Categories