EDN Admin
Well-known member
i am working on an window application to send mail automatically.(Birthday Wishes )
For this i am fetching data from excel sheet to data gridview.
Now i want that a mail is send to each person whose data is fetch from the Excel Sheet. automatically
I am not using SMTP i am using OUTLOOK to send mails
like as below :
<span> <span>private<span> <span>void<span> sendbutton_Click<span>(<span>object<span> sender<span>,<span>
<span>EventArgs<span> e<span>)<span> <br/>
<span>{<span> <br/>
<br/>
<br/>
<span>Outlook<span>.<span>Application<span> oApp
<span>=<span> <span>new<span> <span>Outlook<span>.<span>Application<span>();<span>
<br/>
<span>Outlook<span>.<span>MailItem<span> oMsg
<span>=<span> <span>(<span>Outlook<span>.<span>MailItem<span>)<span>oApp<span>.<span>CreateItem<span>(<span>Outlook<span>.<span>OlItemType<span>.<span>olMailItem<span>);<span>
<br/>
oMsg<span>.<span>HTMLBody<span>
<span>=<span> <span>"Hello,"<span>;<span> <br/>
<span>String<span> sDisplayName <span>=<span>
<span>"MyAttachment"<span>;<span> <br/>
<span>int<span> iPosition <span>=<span> <span>(<span>int<span>)<span>oMsg<span>.<span>Body<span>.<span>Length<span>
<span>+<span> <span>1<span>;<span> <br/>
<span>int<span> iAttachType <span>=<span> <span>(<span>int<span>)<span>Outlook<span>.<span>OlAttachmentType<span>.<span>olByValue<span>;<span>
<br/>
<span>Outlook<span>.<span>Attachment<span> oAttach
<span>=<span> oMsg<span>.<span>Attachments<span>.<span>Add<span>(@<span>"C:\Users\Desktop\maildemo.txt"<span>,<span> iAttachType<span>,<span> iPosition<span>,<span>
sDisplayName<span>);<span> <br/>
oMsg<span>.<span>Subject<span>
<span>=<span> <span>"Your Subject will go here."<span>;<span>
<br/>
<span>Outlook<span>.<span>Recipients<span> oRecips
<span>=<span> <span>(<span>Outlook<span>.<span>Recipients<span>)<span>oMsg<span>.<span>Recipients<span>;<span>
<br/>
<span>Outlook<span>.<span>Recipient<span> oRecip
<span>=<span> <span>(<span>Outlook<span>.<span>Recipient<span>)<span>oRecips<span>.<span>Add<span>(<span>abcd@gmail<span>.<span>com<span>);<span>
<br/>
oRecip<span>.<span>Resolve<span>();<span>
<br/>
oMsg<span>.<span>Send<span>();<span>
<br/>
<br/>
oRecip
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oRecips
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oMsg
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oApp
<span>=<span> <span>null<span>;<span> <br/>
<br/>
<span>MessageBox<span>.<span>Show<span>(<span>"Mail Sent.. Successfully !!"<span>);<span>
<br/>
<span>}
View the full article
For this i am fetching data from excel sheet to data gridview.
Now i want that a mail is send to each person whose data is fetch from the Excel Sheet. automatically
I am not using SMTP i am using OUTLOOK to send mails
like as below :
<span> <span>private<span> <span>void<span> sendbutton_Click<span>(<span>object<span> sender<span>,<span>
<span>EventArgs<span> e<span>)<span> <br/>
<span>{<span> <br/>
<br/>
<br/>
<span>Outlook<span>.<span>Application<span> oApp
<span>=<span> <span>new<span> <span>Outlook<span>.<span>Application<span>();<span>
<br/>
<span>Outlook<span>.<span>MailItem<span> oMsg
<span>=<span> <span>(<span>Outlook<span>.<span>MailItem<span>)<span>oApp<span>.<span>CreateItem<span>(<span>Outlook<span>.<span>OlItemType<span>.<span>olMailItem<span>);<span>
<br/>
oMsg<span>.<span>HTMLBody<span>
<span>=<span> <span>"Hello,"<span>;<span> <br/>
<span>String<span> sDisplayName <span>=<span>
<span>"MyAttachment"<span>;<span> <br/>
<span>int<span> iPosition <span>=<span> <span>(<span>int<span>)<span>oMsg<span>.<span>Body<span>.<span>Length<span>
<span>+<span> <span>1<span>;<span> <br/>
<span>int<span> iAttachType <span>=<span> <span>(<span>int<span>)<span>Outlook<span>.<span>OlAttachmentType<span>.<span>olByValue<span>;<span>
<br/>
<span>Outlook<span>.<span>Attachment<span> oAttach
<span>=<span> oMsg<span>.<span>Attachments<span>.<span>Add<span>(@<span>"C:\Users\Desktop\maildemo.txt"<span>,<span> iAttachType<span>,<span> iPosition<span>,<span>
sDisplayName<span>);<span> <br/>
oMsg<span>.<span>Subject<span>
<span>=<span> <span>"Your Subject will go here."<span>;<span>
<br/>
<span>Outlook<span>.<span>Recipients<span> oRecips
<span>=<span> <span>(<span>Outlook<span>.<span>Recipients<span>)<span>oMsg<span>.<span>Recipients<span>;<span>
<br/>
<span>Outlook<span>.<span>Recipient<span> oRecip
<span>=<span> <span>(<span>Outlook<span>.<span>Recipient<span>)<span>oRecips<span>.<span>Add<span>(<span>abcd@gmail<span>.<span>com<span>);<span>
<br/>
oRecip<span>.<span>Resolve<span>();<span>
<br/>
oMsg<span>.<span>Send<span>();<span>
<br/>
<br/>
oRecip
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oRecips
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oMsg
<span>=<span> <span>null<span>;<span> <br/>
<br/>
oApp
<span>=<span> <span>null<span>;<span> <br/>
<br/>
<span>MessageBox<span>.<span>Show<span>(<span>"Mail Sent.. Successfully !!"<span>);<span>
<br/>
<span>}
View the full article