0

I want to send email over google/gmail from my mvc application after oauth.

I am using mvc 4. My application will ask for authorize this app for oauth. Then I want to send email to other user from the application.

If you help me through code and step to do, that will be great.

Nimish Patel
  • 585
  • 4
  • 17

2 Answers2

0

You can Use Postal which is very handy and easy to use ,to send emails

Controller

dynamic email = new Email("Email");
email.To = UserName;
email.FirstName = FName;
email.LastName = LName;
email.Send();

Then in your View Email

@{
Layout = null;
}

To: @ViewBag.To
From: Example lolcats@website.com
Subject: blah blah

Hello @ViewBag.FirstName,

Your Text.........
This is auto generated email please do not reply.

Edited

Please add your smtp credentials in web.config

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network" from="example@gmail.com">
    <network defaultCredentials="false" host="smtp.gmail.com" port="587" enableSsl="true" userName="example@gmail.com" password="1234567" />
  </smtp>
</mailSettings>
</system.net>

This is very simple. Just give a try Hope this helps!

Kumar
  • 303
  • 6
  • 17
  • Hi. I have installed "Install-Package Postal.Mvc4". Then I have put your code. On line "email.Send();" I am getting error : "Email view not found for Email. Locations searched: ~/Views/Emails/Email.aspx ~/Views/Emails/Email.ascx ~/Views/Shared/Email.aspx ~/Views/Shared/Email.ascx ~/Views/Emails/Email.cshtml ~/Views/Emails/Email.vbhtml ~/Views/Shared/Email.cshtml ~/Views/Shared/Email.vbhtml" – Nimish Patel Nov 17 '14 at 08:54
  • You have not added your View . Please add the View Named 'Email' inside your views folder. And add the view code which is in my answer – Kumar Nov 17 '14 at 08:56
  • Yes added. Now got "SMTP is not specified." We are moving side track. I want to send emails after oauth over SMTP and don't want to open SMTP using credentials. – Nimish Patel Nov 17 '14 at 09:01
  • Edited the answer please check – Kumar Nov 17 '14 at 09:05
0

I have made lots of work out. and Finally.... I have resolved my problem.

In C#, there is no any direct SMTP and Oauth lib. So you need to work manually.

Make Oauth2 access using api and get access "offline".

Then Refer this link SMTP and Oauth

Community
  • 1
  • 1
Nimish Patel
  • 585
  • 4
  • 17