ઝડપી અને સરળ: માં Gmail SMTP સર્વર ની મદદથી ઇમેઇલ મોકલો. નેટ C #

આ બરાબર એક નવો વિષય નથી, પરંતુ હું તે કરવા જરૂરી હોય ત્યારે, I found a lot of “why won’t this work for me” and not too many direct answers. I hope someone finds this useful.

કોડ નીચેના બીટ કરવા મારા પોતાના Gmail એકાઉન્ટ નો ઉપયોગ કરીને ઇમેઇલ મોકલશે, જોડાણો સહિત:

નો ઉપયોગ System.Net.Mail;
નો ઉપયોગ System.Net;

NetworkCredential loginInfo = નવું NetworkCredential("[મારા GMail આઈડી]", "[મારી Gmail પાસવર્ડ]");
MailMessage MSG = નવું MailMessage();
msg.From = નવું MailAddress("[ને એમ Gmail]@ Gmail.com");
msg.To.Add(નવું MailAddress("paul.galvin@arcovis.com"));
msg.Subject = "Test infopath dev subject";
msg.Body = "<HTML><સંસ્થા><મજબૂત>એક મજબૂત સંદેશો.</મજબૂત></સંસ્થા></HTML>";
msg.IsBodyHtml = સાચું;

foreach (સ્ટ્રિંગ aFile માં NIPFD.GetAttachmentNamesAndLocations())
{
    msg.Attachments.Add(નવું ટાંચ(aFile));
} // જોડાણો ઉમેરવાનું.

SmtpClient ક્લાઈન્ટ = નવું SmtpClient("smtp.gmail.com");
client.EnableSsl = સાચું;
client.UseDefaultCredentials = ભૂલ ખવડાવનારું;
client.Credentials = loginInfo;
client.Port = 587;
client.EnableSsl = સાચું;
client.Send(MSG);

થોડા કી બીટ્સ મને નીચે ધીમી અને અન્ય અવલોકનો ક્યે / નોંધો:

  • પ્રથમ વાક્ય ક્વે loginInfo પદાર્થ તોડવામાં આ Gmail ને વાપરવા માટે જરૂર બનાવે છે "@ Gmail.com". તેથી, મારા GMail ઇમેઇલ સરનામું હોય "Sharepoint@gmail.comXyzzy "પછી લીટી જેવો દેખાશે" અને મારો પાસવર્ડ છે ":

NetworkCredential loginInfo = નવું NetworkCredential("sharepoint", "xyzzy");

  • મારી Gmail એકાઉન્ટ SSL વાપરવા માટે સુયોજિત અને ક્યુ સમસ્યા ન હતી થયેલ છે.
  • There is some conflicting information out there on what port to use. I used port 587 અને તે મારા માટે દંડ કામ કર્યું હતું.
  • મારા કિસ્સામાં, I also needed to send attachments. That NIPFD object has a method that knows where my attachments are. It’s returning a fully path (e.g. "કેચ:\કામચલાઉ નોકર attachment1.jpg ". In my test, હું બે જોડાણો હતી અને તેઓ બંને દંડ કામ કર્યું.

હું વિઝ્યુઅલ સ્ટુડિયો ઉપયોગ 2008 આ કોડ લખવા માટે.

</અંત>

મારા બ્લોગ પર સબ્સ્ક્રાઇબ કરો.

Twitter પર મને ખાતે અનુસરો http://www.twitter.com/pagalvin

Technorati ટૅગ્સ: ,,,

2 પર "વિચારોઝડપી અને સરળ: માં Gmail SMTP સર્વર ની મદદથી ઇમેઇલ મોકલો. નેટ C #

  1. જેફ

    આ PowerShell ટીમ બ્લોગ તાજેતરમાં હું એક સર્વર સંચાલક તરીકે અમૂલ્ય મળી એક જ પોસ્ટ હતી. વિઝ્યુઅલ સ્ટુડિયો મહાન પરંતુ મારા સાથીદારોએ ઘણા છે વિકાસકર્તાઓ નથી અને લાયસન્સ ખરીદી નથી. PowerShell વધુ આદેશ વાક્ય જેવી લાગે છે અને તેમને વધુ સુલભ છે. ત્યાં ત્યાં બહાર કોઈપણ સંચાલકો માટે માત્ર એક સૂચન.

    શ્રેષ્ઠ,
    જેફ (www.spjeff.com / @ Spjeff)

    મોકલો-MailMessage સાથે આપોઆપ ઇમેઇલ્સ મોકલી રહ્યું છે

    http://blogs.msdn.com/powershell/archive/2009/10/30/sending-automated-emails-with-send-mailmessage-convertto-html-and-the-powershellpack-s-taskscheduler-module.aspx

એક જવાબ છોડો જેફ જવાબ રદ કરો

તમારું ઇમેઇલ સરનામું પ્રકાશિત કરવામાં આવશે નહીં. જરૂરી ક્ષેત્રો ચિહ્નિત થયેલ છે *