开发者

How to save mail in Sent Items in MS Outlook using VB.Net

i have configured my mail account to Microsoft Outlook, if i send mail from outlook it goes perfectly and a copy is stored in sent items, but when i try to send it from my vb.net windows application the mails are sent in good manner but copy of mail is not stored in sent items, how can i achieve this thanks in advance

my code is as follows

 Dim mail As New MailMessage()
    mail.From = New MailAddress("mail1@test.in")
    mail.To.Add("mail2@test.in")
    mail.Subject = "test"
    mail.Body = "test"
    Dim smtp As New System.Net.Mail.SmtpClient("smtp.rediffmailpro.com", 25)
    smtp.EnableSsl = False
    smtp.Credentials = New System.Net.NetworkCredential("mail1@test.in", "xyz123")
    smtp.Send(mail)
    MsgBox("em开发者_JAVA技巧ail sent")


You are using the System.Net.Mail library which is separate from Outlook. Outlook doesn't know anything about the mail before, during or after it's sent. Which is why there's no message in the Sent Items folder.

If you want the message to show up in Sent Items you need to use Outlook object library itself to send the mail. The code isn't so different from what you've posted. It'll be something like this:

Dim o As New Outlook.Application
Dim item As Outlook.MailItem
item = o.CreateItem(Outlook.OlItemType.olMailItem)
item.Subject = "subject etc"
item.Body = "blah blah"
item.To = "test@test.com"

'to preview to user, for him to manually hit send
item.Display()

or

'to send
item.Send()

You will of course have to reference the Outlook library.

Also depending on your version and config of Outlook it may generate various warnings that a "third party app is trying to send mail".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜